Skip to content

Commit f9fa4b6

Browse files
committed
udpate shimdurabletaskclient and test
1 parent 7e82216 commit f9fa4b6

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

src/Client/OrchestrationServiceClientShim/ShimDurableTaskClient.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,32 +271,28 @@ public override async Task<string> RestartAsync(
271271
throw new ArgumentException($"An orchestration with the instanceId {instanceId} was not found.");
272272
}
273273

274-
// Create options for the new orchestration
275-
StartOrchestrationOptions options;
276-
if (!restartWithNewInstanceId)
277-
{
278-
options = new StartOrchestrationOptions()
279-
{
280-
InstanceId = instanceId,
281-
};
282-
}
283-
else
274+
// Determine the instance ID for the restarted orchestration
275+
string newInstanceId = restartWithNewInstanceId ? Guid.NewGuid().ToString("N") : instanceId;
276+
277+
OrchestrationInstance instance = new()
284278
{
285-
options = new StartOrchestrationOptions();
286-
}
279+
InstanceId = newInstanceId,
280+
ExecutionId = Guid.NewGuid().ToString("N"),
281+
};
287282

288-
object? input = null;
289-
if (!string.IsNullOrEmpty(status.SerializedInput))
283+
// Use the original serialized input directly to avoid double serialization
284+
TaskMessage message = new()
290285
{
291-
input = this.DataConverter.Deserialize(status.SerializedInput, typeof(object));
292-
}
286+
OrchestrationInstance = instance,
287+
Event = new ExecutionStartedEvent(-1, status.SerializedInput)
288+
{
289+
Name = status.Name,
290+
OrchestrationInstance = instance,
291+
},
292+
};
293293

294-
// Start a new orchestration with the same name and input
295-
return await this.ScheduleNewOrchestrationInstanceAsync(
296-
new TaskName(status.Name),
297-
input,
298-
options,
299-
cancellation);
294+
await this.Client.CreateTaskOrchestrationAsync(message);
295+
return newInstanceId;
300296
}
301297

302298
[return: NotNullIfNotNull("state")]

test/Client/OrchestrationServiceClientShim.Tests/ShimDurableTaskClientTests.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,11 @@ public async Task RestartAsync_EndToEnd(bool restartWithNewInstanceId)
347347
.Setup(x => x.GetOrchestrationStateAsync(originalInstanceId, false))
348348
.ReturnsAsync(new List<Core.OrchestrationState> { originalState });
349349

350-
// Setup the mock for the new orchestration creation
350+
// Capture the TaskMessage for verification becasue we will create this message at RestartAsync.
351+
TaskMessage? capturedMessage = null;
351352
this.orchestrationClient
352353
.Setup(x => x.CreateTaskOrchestrationAsync(It.IsAny<TaskMessage>()))
354+
.Callback<TaskMessage>(msg => capturedMessage = msg)
353355
.Returns(Task.CompletedTask);
354356

355357
string restartedInstanceId = await this.client.RestartAsync(originalInstanceId, restartWithNewInstanceId);
@@ -363,16 +365,21 @@ public async Task RestartAsync_EndToEnd(bool restartWithNewInstanceId)
363365
restartedInstanceId.Should().Be(originalInstanceId);
364366
}
365367

366-
// Verify that CreateTaskOrchestrationAsync was called with the correct parameters
368+
// Verify that CreateTaskOrchestrationAsync was called
367369
this.orchestrationClient.Verify(
368-
x => x.CreateTaskOrchestrationAsync(It.Is<TaskMessage>(msg =>
369-
msg.Event is ExecutionStartedEvent startedEvent &&
370-
startedEvent.Name == orchestratorName &&
371-
startedEvent.Input == serializedInput &&
372-
(restartWithNewInstanceId ?
373-
msg.OrchestrationInstance.InstanceId != originalInstanceId :
374-
msg.OrchestrationInstance.InstanceId == originalInstanceId))),
370+
x => x.CreateTaskOrchestrationAsync(It.IsAny<TaskMessage>()),
375371
Times.Once);
372+
373+
// Verify the captured message details
374+
capturedMessage.Should().NotBeNull();
375+
capturedMessage!.Event.Should().BeOfType<ExecutionStartedEvent>();
376+
377+
var startedEvent = (ExecutionStartedEvent)capturedMessage.Event;
378+
startedEvent.Name.Should().Be(orchestratorName);
379+
startedEvent.Input.Should().Be(serializedInput);
380+
startedEvent.OrchestrationInstance.InstanceId.Should().Be(restartedInstanceId);
381+
startedEvent.OrchestrationInstance.ExecutionId.Should().NotBeNullOrEmpty();
382+
startedEvent.OrchestrationInstance.ExecutionId.Should().NotBe(originalState.OrchestrationInstance.ExecutionId);
376383
}
377384

378385
[Fact]

0 commit comments

Comments
 (0)