From 09be6e6706fb534143f6a6313265964daa6885ef Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Fri, 2 Jan 2026 08:32:57 +0100 Subject: [PATCH 1/2] Use timeout in WaitforReady function --- playground/local_runner.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/playground/local_runner.go b/playground/local_runner.go index fd6091e..29055f4 100644 --- a/playground/local_runner.go +++ b/playground/local_runner.go @@ -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 From 8044bf31fb83ec66a77576ef20240acf6dacaa19 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Fri, 2 Jan 2026 08:36:10 +0100 Subject: [PATCH 2/2] Add unit tests --- playground/local_runner_test.go | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/playground/local_runner_test.go b/playground/local_runner_test.go index 04b4b51..8a9ae57 100644 --- a/playground/local_runner_test.go +++ b/playground/local_runner_test.go @@ -3,6 +3,7 @@ package playground import ( "context" "testing" + "time" "github.com/docker/docker/api/types/image" "github.com/stretchr/testify/require" @@ -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) +}