Skip to content
Merged
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
3 changes: 3 additions & 0 deletions playground/local_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func (d *LocalRunner) WaitForReady(ctx context.Context, timeout time.Duration) e
case <-ctx.Done():
return ctx.Err()

case <-time.After(timeout):
return fmt.Errorf("timeout")

case <-time.After(1 * time.Second):
if d.AreReady() {
return nil
Expand Down
49 changes: 49 additions & 0 deletions playground/local_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package playground
import (
"context"
"testing"
"time"

"github.com/docker/docker/api/types/image"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -49,3 +50,51 @@ func TestRunnerPullImages(t *testing.T) {
// 2 'pulling image' + 2 'image pulled'
require.Equal(t, numEvents, 4)
}

func TestWaitForReady_Timeout(t *testing.T) {
// Create a runner with a service that never becomes ready
manifest := &Manifest{
Services: []*Service{
{Name: "never-ready"},
},
}

cfg := &RunnerConfig{
Manifest: manifest,
}
runner, err := NewLocalRunner(cfg)
require.NoError(t, err)

// Mark service as started but not ready
runner.updateTaskStatus("never-ready", TaskStatusStarted)

ctx := context.Background()
err = runner.WaitForReady(ctx, 500*time.Millisecond)
require.Error(t, err)
require.Equal(t, "timeout", err.Error())
}

func TestWaitForReady_Success(t *testing.T) {
// Create a runner with a service that becomes ready
manifest := &Manifest{
Services: []*Service{
{Name: "ready-service"},
},
}

cfg := &RunnerConfig{
Manifest: manifest,
}
runner, err := NewLocalRunner(cfg)
require.NoError(t, err)

// Service becomes ready after a delay
go func() {
time.Sleep(200 * time.Millisecond)
runner.updateTaskStatus("ready-service", TaskStatusStarted)
}()

ctx := context.Background()
err = runner.WaitForReady(ctx, 2*time.Second)
require.NoError(t, err)
}