Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go-sdk/pkg/worker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (h *heartbeater) Run(
var httpError *api.GeneralHTTPError
if errors.As(err, &httpError) {
resp := httpError.Response
if resp != nil && resp.StatusCode() == 404 || resp.StatusCode() == 409 {
if resp != nil && (resp.StatusCode() == 404 || resp.StatusCode() == 409) {
h.logger.ErrorContext(
ctx,
"Server indicated the task shouldn't be running anymore",
Expand Down
33 changes: 33 additions & 0 deletions go-sdk/pkg/worker/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,39 @@ func (s *WorkerSuite) TestTaskHeartbeatConflictStopsTask() {
s.NoError(err)
}

func (s *WorkerSuite) TestTaskHeartbeatNilResponseDoesNotPanic() {
id := uuid.New().String()
testWorkload := newTestWorkLoad(id, id[:8])

var callCount atomic.Int32
secondHeartbeat := make(chan struct{})

s.registry.AddDag(testWorkload.TI.DagId).
AddTaskWithName(testWorkload.TI.TaskId, func() error {
select {
case <-secondHeartbeat:
return nil
case <-time.After(2 * time.Second):
return fmt.Errorf("second heartbeat was never observed")
}
})

s.ExpectTaskRun(id)
s.ExpectTaskState(id, api.TerminalTIStateSuccess)
s.ti.EXPECT().
Heartbeat(mock.Anything, uuid.MustParse(id), mock.Anything).
RunAndReturn(func(ctx context.Context, taskInstanceId uuid.UUID, body *api.TIHeartbeatInfo) error {
if callCount.Add(1) == 2 {
close(secondHeartbeat)
}
return &api.GeneralHTTPError{Response: nil}
})
s.client.EXPECT().TaskInstances().Return(s.ti)

err := s.worker.ExecuteTaskWorkload(context.Background(), testWorkload)
s.NoError(err, "ExecuteTaskWorkload should not report an error")
}

func (s *WorkerSuite) TestTaskHeartbeatErrorStopsTaskAndLogs() {
s.T().Skip("TODO: Not implemented yet")
}
Expand Down
Loading