From b5ec427892adfdaa84f72a5a6fab2c652aa5f415 Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Mon, 14 Jul 2014 14:26:30 -0700 Subject: [PATCH] Add Once test --- utils_test.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/utils_test.go b/utils_test.go index 8118cb8aa..d8edcc0d6 100644 --- a/utils_test.go +++ b/utils_test.go @@ -11,7 +11,7 @@ func TestEvery(t *testing.T) { Every(2*time.Millisecond, func() { i++ }) - time.Sleep(5 * time.Millisecond) + <-time.After(5 * time.Millisecond) Expect(t, i, 2) } @@ -20,7 +20,7 @@ func TestAfter(t *testing.T) { After(1*time.Millisecond, func() { i++ }) - time.Sleep(2 * time.Millisecond) + <-time.After(2 * time.Millisecond) Expect(t, i, 1) } @@ -41,9 +41,24 @@ func TestOn(t *testing.T) { i = data.(int) }) Publish(e, 10) - time.Sleep(1 * time.Millisecond) + <-time.After(1 * time.Millisecond) Expect(t, i, 10) } +func TestOnce(t *testing.T) { + i := 0 + e := NewEvent() + Once(e, func(data interface{}) { + i += data.(int) + }) + On(e, func(data interface{}) { + i += data.(int) + }) + Publish(e, 10) + <-time.After(1 * time.Millisecond) + Publish(e, 10) + <-time.After(1 * time.Millisecond) + Expect(t, i, 30) +} func TestFromScale(t *testing.T) { Expect(t, FromScale(5, 0, 10), 0.5)