Skip to content

Commit 315dc3d

Browse files
committed
update test
1 parent f9fa4b6 commit 315dc3d

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

test/Grpc.IntegrationTests/GrpcDurableTaskClientIntegrationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ public async Task RestartAsync_EndToEnd(bool restartWithNewInstanceId)
231231
{
232232
await using HostTestLifetime server = await this.StartAsync();
233233

234-
// Start an initial orchestration
234+
// Start an initial orchestration with shouldThrow = false to ensure it completes successfully
235235
string originalInstanceId = await server.Client.ScheduleNewOrchestrationInstanceAsync(
236-
OrchestrationName, input: "test-input");
236+
OrchestrationName, input: false);
237237

238238
// Wait for it to start and then complete
239239
await server.Client.WaitForInstanceStartAsync(originalInstanceId, default);
@@ -265,7 +265,7 @@ public async Task RestartAsync_EndToEnd(bool restartWithNewInstanceId)
265265
OrchestrationMetadata? restartedMetadata = await server.Client.GetInstanceAsync(restartedInstanceId, true);
266266
restartedMetadata.Should().NotBeNull();
267267
restartedMetadata!.Name.Should().Be(OrchestrationName);
268-
restartedMetadata.SerializedInput.Should().Be("\"test-input\"");
268+
restartedMetadata.SerializedInput.Should().Be("false");
269269

270270
// Complete the restarted orchestration
271271
await server.Client.RaiseEventAsync(restartedInstanceId, "event", default);

test/Grpc.IntegrationTests/GrpcSidecar/Grpc/TaskHubGrpcServer.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,60 @@ static P.GetInstanceResponse CreateGetInstanceResponse(OrchestrationState state,
333333
return new P.ResumeResponse();
334334
}
335335

336+
public override async Task<P.RestartInstanceResponse> RestartInstance(P.RestartInstanceRequest request, ServerCallContext context)
337+
{
338+
try
339+
{
340+
// Get the original orchestration state
341+
IList<OrchestrationState> states = await this.client.GetOrchestrationStateAsync(request.InstanceId, false);
342+
if (states == null || states.Count == 0)
343+
{
344+
throw new RpcException(new Status(StatusCode.NotFound, $"An orchestration with the instanceId {request.InstanceId} was not found."));
345+
}
346+
347+
OrchestrationState state = states[0];
348+
string newInstanceId = request.RestartWithNewInstanceId ? Guid.NewGuid().ToString("N") : request.InstanceId;
349+
350+
// Create a new orchestration instance
351+
OrchestrationInstance newInstance = new()
352+
{
353+
InstanceId = newInstanceId,
354+
ExecutionId = Guid.NewGuid().ToString("N"),
355+
};
356+
357+
// Create an ExecutionStartedEvent with the original input
358+
ExecutionStartedEvent startedEvent = new(-1, state.Name)
359+
{
360+
Input = state.Input, // Use the original serialized input
361+
Version = state.Version ?? string.Empty,
362+
OrchestrationInstance = newInstance,
363+
};
364+
365+
TaskMessage taskMessage = new()
366+
{
367+
OrchestrationInstance = newInstance,
368+
Event = startedEvent,
369+
};
370+
371+
await this.client.CreateTaskOrchestrationAsync(taskMessage);
372+
373+
return new P.RestartInstanceResponse
374+
{
375+
InstanceId = newInstanceId,
376+
};
377+
}
378+
catch (RpcException)
379+
{
380+
// Re-throw RpcException as-is
381+
throw;
382+
}
383+
catch (Exception ex)
384+
{
385+
this.log.LogError(ex, "Error restarting orchestration instance {InstanceId}", request.InstanceId);
386+
throw new RpcException(new Status(StatusCode.Internal, ex.Message));
387+
}
388+
}
389+
336390
static P.TaskFailureDetails? GetFailureDetails(FailureDetails? failureDetails)
337391
{
338392
if (failureDetails == null)

0 commit comments

Comments
 (0)