Skip to content

Commit

Permalink
Executor: Adds WaitForInstanceStart to StartIntance (#15)
Browse files Browse the repository at this point in the history
* Executor: Adds WaitForInstanceStart to StartIntance

Signed-off-by: joshvanl <me@joshvanl.dev>

* Update tests to account for start waiting for the orchestration state to
become non-pending

Signed-off-by: joshvanl <me@joshvanl.dev>

---------

Signed-off-by: joshvanl <me@joshvanl.dev>
  • Loading branch information
JoshVanL authored Feb 7, 2025
1 parent d9f84c6 commit 3dabfe5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions backend/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ func (g *grpcExecutor) StartInstance(ctx context.Context, req *protos.CreateInst
return nil, err
}

_, err := g.WaitForInstanceStart(ctx, &protos.GetInstanceRequest{InstanceId: instanceID})
if err != nil {
return nil, err
}

return &protos.CreateInstanceResponse{InstanceId: instanceID}, nil
}

Expand Down
12 changes: 5 additions & 7 deletions tests/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ func Test_Grpc_WaitForInstanceStart_Timeout(t *testing.T) {
cancelListener := startGrpcListener(t, r)
defer cancelListener()

id, err := grpcClient.ScheduleNewOrchestration(ctx, "WaitForInstanceStartThrowsException", api.WithInput("世界"))
require.NoError(t, err)
go grpcClient.ScheduleNewOrchestration(ctx, "WaitForInstanceStartThrowsException", api.WithInput("世界"), api.WithInstanceID("helloworld"))
timeoutCtx, cancelTimeout := context.WithTimeout(ctx, time.Second)
defer cancelTimeout()
_, err = grpcClient.WaitForOrchestrationStart(timeoutCtx, id, api.WithFetchPayloads(true))
_, err := grpcClient.WaitForOrchestrationStart(timeoutCtx, "helloworld", api.WithFetchPayloads(true))
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "context deadline exceeded")
}
Expand All @@ -121,11 +120,10 @@ func Test_Grpc_WaitForInstanceStart_ConnectionResume(t *testing.T) {

cancelListener := startGrpcListener(t, r)

id, err := grpcClient.ScheduleNewOrchestration(ctx, "WaitForInstanceStartThrowsException", api.WithInput("世界"))
require.NoError(t, err)
go grpcClient.ScheduleNewOrchestration(ctx, "WaitForInstanceStartThrowsException", api.WithInput("世界"), api.WithInstanceID("worldhello"))
timeoutCtx, cancelTimeout := context.WithTimeout(ctx, time.Second)
defer cancelTimeout()
_, err = grpcClient.WaitForOrchestrationStart(timeoutCtx, id, api.WithFetchPayloads(true))
_, err := grpcClient.WaitForOrchestrationStart(timeoutCtx, "worldhello", api.WithFetchPayloads(true))
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "context deadline exceeded")
}
Expand All @@ -139,7 +137,7 @@ func Test_Grpc_WaitForInstanceStart_ConnectionResume(t *testing.T) {
// workitem should be retried and completed.
timeoutCtx, cancelTimeout = context.WithTimeout(ctx, 30*time.Second)
defer cancelTimeout()
metadata, err := grpcClient.WaitForOrchestrationCompletion(timeoutCtx, id, api.WithFetchPayloads(true))
metadata, err := grpcClient.WaitForOrchestrationCompletion(timeoutCtx, "worldhello", api.WithFetchPayloads(true))
require.NoError(t, err)
assert.True(t, api.OrchestrationMetadataIsComplete(metadata))
assert.Equal(t, "42", metadata.Output.Value)
Expand Down

0 comments on commit 3dabfe5

Please sign in to comment.