From b72aeaa3f07625d98ea91b4fe5e226cab9cf5773 Mon Sep 17 00:00:00 2001 From: Umputun Date: Wed, 29 May 2019 22:32:00 -0500 Subject: [PATCH] simplify test --- app/agent/demo_mode_test.go | 6 +++--- app/agent/docker_logger_test.go | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/agent/demo_mode_test.go b/app/agent/demo_mode_test.go index 0aa5729..3b67460 100644 --- a/app/agent/demo_mode_test.go +++ b/app/agent/demo_mode_test.go @@ -15,10 +15,10 @@ import ( func TestDemoEmitter_Logs(t *testing.T) { d := DemoEmitter{time.Millisecond * 100} wr := mockDemoWriter{} - ctx, cancel := context.WithCancel(context.Background()) - time.AfterFunc(time.Millisecond*1090, cancel) + ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*1090) + defer cancel() err := d.Logs(docker.LogsOptions{Context: ctx, OutputStream: &wr}) - assert.EqualError(t, err, "context canceled") + assert.EqualError(t, err, "context deadline exceeded") t.Logf("%+v", wr.Get()) assert.Equal(t, 10+1, len(wr.Get()), "10 messages with extra \n") } diff --git a/app/agent/docker_logger_test.go b/app/agent/docker_logger_test.go index 2591c67..686855f 100644 --- a/app/agent/docker_logger_test.go +++ b/app/agent/docker_logger_test.go @@ -23,9 +23,7 @@ func TestLogger_WithError(t *testing.T) { assert.EqualError(t, e, "context canceled", e.Error()) }() time.Sleep(10 * time.Millisecond) - time.AfterFunc(time.Second, func() { - cancel() - }) + time.AfterFunc(time.Second, cancel) l.Wait() assert.True(t, time.Since(st) < time.Second*2, "terminated early") time.Sleep(10 * time.Millisecond)