From 837cfe3223db11bf7f5edb6ba738d3e328b80ea2 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Sun, 12 Jan 2020 16:40:01 +0300 Subject: Refactored New clean API Timeouts and restart limits --- rutina_test.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'rutina_test.go') diff --git a/rutina_test.go b/rutina_test.go index 0c6d94a..3cbdf40 100755 --- a/rutina_test.go +++ b/rutina_test.go @@ -8,10 +8,7 @@ import ( ) func TestSuccess(t *testing.T) { - r := New( - WithStdLogger(), - WithContext(context.Background()), - ) + r := New(nil) counter := 0 f := func(name string, ttl time.Duration) error { counter++ @@ -22,13 +19,13 @@ func TestSuccess(t *testing.T) { } r.Go(func(ctx context.Context) error { return f("one", 1*time.Second) - }) + }, nil) r.Go(func(ctx context.Context) error { return f("two", 2*time.Second) - }) + }, nil) r.Go(func(ctx context.Context) error { return f("three", 3*time.Second) - }) + }, nil) if err := r.Wait(); err != nil { t.Error("Unexpected error", err) } @@ -40,7 +37,7 @@ func TestSuccess(t *testing.T) { } func TestError(t *testing.T) { - r := New() + r := New(nil) f := func(name string, ttl time.Duration) error { <-time.After(ttl) t.Log(name) @@ -48,13 +45,13 @@ func TestError(t *testing.T) { } r.Go(func(ctx context.Context) error { return f("one", 1*time.Second) - }) + }, nil) r.Go(func(ctx context.Context) error { return f("two", 2*time.Second) - }) + }, nil) r.Go(func(ctx context.Context) error { return f("three", 3*time.Second) - }) + }, nil) if err := r.Wait(); err != nil { if err.Error() != "error from one" { t.Error("Must be error from first routine") @@ -65,12 +62,12 @@ func TestError(t *testing.T) { } func TestContext(t *testing.T) { - r := New() + r := New(nil) cc := false r.Go(func(ctx context.Context) error { <-time.After(1 * time.Second) return nil - }, ShutdownIfDone) + }, RunOpt.SetOnDone(Shutdown)) r.Go(func(ctx context.Context) error { select { case <-ctx.Done(): @@ -79,7 +76,7 @@ func TestContext(t *testing.T) { case <-time.After(3 * time.Second): return errors.New("Timeout") } - }, ShutdownIfDone) + }, nil) if err := r.Wait(); err != nil { t.Error("Unexpected error", err) } -- cgit v1.2.3