diff options
author | obscuren <geffobscura@gmail.com> | 2014-09-29 18:57:51 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-09-29 18:57:51 +0800 |
commit | ab6ede51d7fedb9270cab08ee732a834be34dab2 (patch) | |
tree | d8252f27d51c456e637140a312cadfe2ced71528 /eventer/eventer_test.go | |
parent | ea0357bf02b61db94bd0ad8806ba7337a55a4f79 (diff) | |
download | dexon-ab6ede51d7fedb9270cab08ee732a834be34dab2.tar dexon-ab6ede51d7fedb9270cab08ee732a834be34dab2.tar.gz dexon-ab6ede51d7fedb9270cab08ee732a834be34dab2.tar.bz2 dexon-ab6ede51d7fedb9270cab08ee732a834be34dab2.tar.lz dexon-ab6ede51d7fedb9270cab08ee732a834be34dab2.tar.xz dexon-ab6ede51d7fedb9270cab08ee732a834be34dab2.tar.zst dexon-ab6ede51d7fedb9270cab08ee732a834be34dab2.zip |
Working on new (blocking) event machine.
The new event machine will be used for loose coupling and handle the
communications between the services:
1) Block pool finds blocks which "links" with our current canonical
chain
2) Posts the blocks on to the event machine
3) State manager receives blocks & processes them
4) Broadcasts new post block event
Diffstat (limited to 'eventer/eventer_test.go')
-rw-r--r-- | eventer/eventer_test.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/eventer/eventer_test.go b/eventer/eventer_test.go new file mode 100644 index 000000000..b35267af6 --- /dev/null +++ b/eventer/eventer_test.go @@ -0,0 +1,66 @@ +package eventer + +import "testing" + +func TestChannel(t *testing.T) { + eventer := New(nil) + + c := make(Channel, 1) + eventer.RegisterChannel("test", c) + eventer.Post("test", "hello world") + + res := <-c + + if res.Data.(string) != "hello world" { + t.Error("Expected event with data 'hello world'. Got", res.Data) + } +} + +func TestFunction(t *testing.T) { + eventer := New(nil) + + var data string + eventer.RegisterFunc("test", func(ev Event) { + data = ev.Data.(string) + }) + eventer.Post("test", "hello world") + + if data != "hello world" { + t.Error("Expected event with data 'hello world'. Got", data) + } +} + +func TestRegister(t *testing.T) { + eventer := New(nil) + + c := eventer.Register("test") + eventer.Post("test", "hello world") + + res := <-c + + if res.Data.(string) != "hello world" { + t.Error("Expected event with data 'hello world'. Got", res.Data) + } +} + +func TestOn(t *testing.T) { + eventer := New(nil) + + c := make(Channel, 1) + eventer.On("test", c) + + var data string + eventer.On("test", func(ev Event) { + data = ev.Data.(string) + }) + eventer.Post("test", "hello world") + + res := <-c + if res.Data.(string) != "hello world" { + t.Error("Expected channel event with data 'hello world'. Got", res.Data) + } + + if data != "hello world" { + t.Error("Expected function event with data 'hello world'. Got", data) + } +} |