Skip to content

Commit

Permalink
fix: waiting for service pod
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Nov 28, 2024
1 parent cccfcb7 commit c4658c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ func main() {
getTestWorkflowServiceNotificationsStream := func(ctx context.Context, executionID, serviceName string, serviceIndex int) (<-chan testkube.TestWorkflowExecutionNotification, error) {
execution, err := testWorkflowResultsRepository.Get(ctx, executionID)
if err != nil {
return nil, errors.Join(err, agent.ErrGetTestWorkflowExecution)
return nil, err
}

if execution.Result != nil && execution.Result.IsFinished() {
return nil, agent.ErrFinishedTestWorkflowExecution
return nil, errors.New("test workflow execution is finished")
}

notifications := executionWorker.Notifications(ctx, fmt.Sprintf("%s-%s-%d", execution.Id, serviceName, serviceIndex), executionworkertypes.NotificationsOptions{
Expand Down
12 changes: 2 additions & 10 deletions pkg/agent/testworkflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ import (
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/cloud"
"github.com/kubeshop/testkube/pkg/testworkflows/executionworker/controller"
"github.com/kubeshop/testkube/pkg/testworkflows/executionworker/registry"
)

const testWorkflowNotificationsRetryCount = 10

var (
ErrGetTestWorkflowExecution = errors.New("can't get test workflow execution")
ErrFinishedTestWorkflowExecution = errors.New("test workflow execution is finished")
)

func getTestWorkflowNotificationType(n testkube.TestWorkflowExecutionNotification) cloud.TestWorkflowNotificationType {
if n.Result != nil {
return cloud.TestWorkflowNotificationType_WORKFLOW_STREAM_RESULT
Expand Down Expand Up @@ -248,11 +244,7 @@ func (ag *Agent) executeWorkflowServiceNotificationsRequest(ctx context.Context,

for {
notificationsCh, err = ag.testWorkflowServiceNotificationsFunc(ctx, req.ExecutionId, req.ServiceName, int(req.ServiceIndex))
if errors.Is(err, ErrGetTestWorkflowExecution) || errors.Is(err, ErrFinishedTestWorkflowExecution) {
break
}

if err != nil {
if errors.Is(err, registry.ErrResourceNotFound) {
// We have a race condition here
// Cloud sometimes slow to start service
// while WorkflowNotifications request from websockets comes in faster
Expand Down

0 comments on commit c4658c5

Please sign in to comment.