Infinite busy waiting for lost event (#31)
* Close evaluation stream for Nomad Job creation when set event handler have been finished * Remove evaluation event stream requests by handling the events via the main Nomad event handler.
This commit is contained in:
@@ -177,7 +177,9 @@ func (n *NomadEnvironment) Register(apiClient nomad.ExecutorAPI) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't register job: %w", err)
|
||||
}
|
||||
err = apiClient.MonitorEvaluation(evalID, context.Background())
|
||||
ctx, cancel := context.WithTimeout(context.Background(), nomad.RegisterTimeout)
|
||||
defer cancel()
|
||||
err = apiClient.MonitorEvaluation(evalID, ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during the monitoring of the environment job: %w", err)
|
||||
}
|
||||
|
@@ -116,24 +116,15 @@ func TestRegisterFailsWhenNomadJobRegistrationFails(t *testing.T) {
|
||||
err := environment.Register(apiClientMock)
|
||||
|
||||
assert.ErrorIs(t, err, expectedErr)
|
||||
apiClientMock.AssertNotCalled(t, "EvaluationStream")
|
||||
apiClientMock.AssertNotCalled(t, "MonitorEvaluation")
|
||||
}
|
||||
|
||||
func TestRegisterTemplateJobSucceedsWhenMonitoringEvaluationSucceeds(t *testing.T) {
|
||||
apiClientMock := &nomad.ExecutorAPIMock{}
|
||||
evaluationID := "id"
|
||||
|
||||
stream := make(chan *nomadApi.Events)
|
||||
readonlyStream := func() <-chan *nomadApi.Events {
|
||||
return stream
|
||||
}()
|
||||
// Immediately close stream to avoid any reading from it resulting in endless wait
|
||||
close(stream)
|
||||
|
||||
apiClientMock.On("RegisterNomadJob", mock.AnythingOfType("*api.Job")).Return(evaluationID, nil)
|
||||
apiClientMock.On("MonitorEvaluation", mock.AnythingOfType("string"), mock.Anything).Return(nil)
|
||||
apiClientMock.On("EvaluationStream", evaluationID, mock.AnythingOfType("*context.emptyCtx")).
|
||||
Return(readonlyStream, nil)
|
||||
|
||||
environment := &NomadEnvironment{"", &nomadApi.Job{}, nil}
|
||||
environment.SetID(tests.DefaultEnvironmentIDAsInteger)
|
||||
|
@@ -232,7 +232,7 @@ func TestNomadEnvironmentManager_List(t *testing.T) {
|
||||
}
|
||||
|
||||
func mockWatchAllocations(apiMock *nomad.ExecutorAPIMock) {
|
||||
call := apiMock.On("WatchAllocations", mock.Anything, mock.Anything, mock.Anything)
|
||||
call := apiMock.On("WatchEventStream", mock.Anything, mock.Anything, mock.Anything)
|
||||
call.Run(func(args mock.Arguments) {
|
||||
<-time.After(10 * time.Minute) // 10 minutes is the default test timeout
|
||||
call.ReturnArguments = mock.Arguments{nil}
|
||||
|
Reference in New Issue
Block a user