Skip to content

Commit 29d5535

Browse files
fixing test
1 parent 69f32b9 commit 29d5535

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

src/ServiceControl.AcceptanceTests/Recoverability/ExternalIntegration/When_a_failed_edit_is_resolved_by_retry.cs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ public async Task Should_publish_notification()
4040
return false;
4141
}
4242

43-
if (!ctx.OriginalMessageHandled)
43+
if (!ctx.OriginalMessageHasBeenHandled)
4444
{
4545
return false;
4646
}
4747

48-
if (!ctx.EditedAndRetriedMessage)
48+
// second message - edit & retry
49+
if (!ctx.EditedMessageHasBeenSent)
4950
{
5051
var failedMessagedId = await this.GetOnlyFailedUnresolvedMessageId();
5152
if (failedMessagedId == null)
@@ -54,11 +55,11 @@ public async Task Should_publish_notification()
5455
}
5556

5657
ctx.OriginalMessageFailureId = failedMessagedId;
57-
ctx.EditedAndRetriedMessage = true;
58+
ctx.EditedMessageHasBeenSent = true;
5859

5960
string editedMessage = JsonSerializer.Serialize(new EditResolutionMessage
6061
{
61-
HasBeenEdited = true
62+
ThisIsAnEditedMessage = true
6263
});
6364

6465
SingleResult<FailedMessage> failedMessage =
@@ -73,7 +74,13 @@ public async Task Should_publish_notification()
7374
return false;
7475
}
7576

76-
if (!ctx.RetriedMessage)
77+
if (!ctx.EditedAndRetriedMessageHandled)
78+
{
79+
return false;
80+
}
81+
82+
// third message - retry
83+
if (!ctx.RetriedMessageHasBeenSent)
7784
{
7885
var failedMessageIdAfterId = await this.GetOnlyFailedUnresolvedMessageId();
7986
if (failedMessageIdAfterId == null)
@@ -82,18 +89,24 @@ public async Task Should_publish_notification()
8289
}
8390

8491
ctx.EditedMessageFailureId = failedMessageIdAfterId;
85-
ctx.RetriedMessage = true;
92+
ctx.RetriedMessageHasBeenSent = true;
93+
ctx.NeedToHandleRetriedMessage = true;
8694

8795
await this.Post<object>($"/api/errors/{ctx.EditedMessageFailureId}/retry");
8896
return false;
8997
}
9098

91-
if (!ctx.RetriedMessageHandled || ctx.EditedMessageEditOf == null)
99+
if (!ctx.RetriedMessageHandled)
92100
{
93101
return false;
94102
}
95103

96-
if (!ctx.EditedAndRetriedMessgaeHandled || !ctx.MessageResolved)
104+
if (ctx.EditedMessageEditOf == null)
105+
{
106+
return false;
107+
}
108+
109+
if (!ctx.MessageResolved)
97110
{
98111
return false;
99112
}
@@ -111,18 +124,19 @@ public async Task Should_publish_notification()
111124

112125
public class EditMessageResolutionContext : ScenarioContext
113126
{
114-
public bool OriginalMessageHandled { get; set; }
127+
public bool OriginalMessageHasBeenHandled { get; set; }
115128
public string OriginalMessageFailureId { get; set; }
116129

117130
public string ResolvedMessageId { get; set; }
118131
public bool MessageResolved { get; set; }
119-
public bool EditedAndRetriedMessgaeHandled { get; set; }
132+
public bool EditedAndRetriedMessageHandled { get; set; }
120133
public bool RetriedMessageHandled { get; set; }
121134
public string EditedMessageFailureId { get; set; }
122-
public bool EditedAndRetriedMessage { get; set; }
123-
public bool RetriedMessage { get; set; }
135+
public bool EditedMessageHasBeenSent { get; set; }
136+
public bool RetriedMessageHasBeenSent { get; set; }
124137
public string EditedMessageEditOf { get; set; }
125138
public bool ExternalProcessorSubscribed { get; set; }
139+
public bool NeedToHandleRetriedMessage { get; set; }
126140
}
127141

128142
public class MessageReceiver : EndpointConfigurationBuilder
@@ -135,21 +149,22 @@ public class EditMessageResolutionHandler(EditMessageResolutionContext testConte
135149
{
136150
public Task Handle(EditResolutionMessage message, IMessageHandlerContext context)
137151
{
138-
if (!message.HasBeenEdited)
152+
// First run - supposed to fail
153+
if (!message.ThisIsAnEditedMessage)
139154
{
140-
testContext.OriginalMessageHandled = true;
155+
testContext.OriginalMessageHasBeenHandled = true;
141156
throw new SimulatedException();
142157
}
143158

144-
if (!testContext.RetriedMessage)
159+
// Second run - edit retry - supposed to fail
160+
if (!testContext.NeedToHandleRetriedMessage)
145161
{
146162
testContext.EditedMessageEditOf = context.MessageHeaders["ServiceControl.EditOf"];
147-
;
148-
testContext.EditedAndRetriedMessgaeHandled = true;
163+
testContext.EditedAndRetriedMessageHandled = true;
149164
throw new SimulatedException();
150165
}
151166

152-
167+
// Last run - normal retry - supposed to succeed
153168
testContext.RetriedMessageHandled = true;
154169
return Task.CompletedTask;
155170
}
@@ -165,7 +180,7 @@ public Task Handle(MessageFailureResolvedByRetry message, IMessageHandlerContext
165180

166181
public class EditResolutionMessage : IMessage
167182
{
168-
public bool HasBeenEdited { get; init; }
183+
public bool ThisIsAnEditedMessage { get; init; }
169184
}
170185
}
171186
}

src/ServiceControl.AcceptanceTests/Recoverability/ExternalIntegration/When_a_reedit_solves_a_failed_msg.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace ServiceControl.AcceptanceTests.Recoverability.ExternalIntegration
1515
class When_a_reedit_solves_a_failed_msg : AcceptanceTest
1616
{
1717
[Test]
18-
// [Ignore("testing another approach")]
18+
[Ignore("testing another approach")]
1919
public async Task Should_publish_notification()
2020
{
2121
CustomConfiguration = config => config.OnEndpointSubscribed<EditMessageResolutionContext>((s, ctx) =>

0 commit comments

Comments
 (0)