mirror of
https://github.com/pocke/goevent.git
synced 2025-05-04 22:18:02 +08:00
test
This commit is contained in:
parent
b16e211d60
commit
2d7d6f14ab
48
pfs_test.go
48
pfs_test.go
@ -1,6 +1,7 @@
|
|||||||
package pfs_test
|
package pfs_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pocke/pfs"
|
"github.com/pocke/pfs"
|
||||||
@ -22,11 +23,46 @@ func TestPubSub(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Pub(2)
|
ok := p.Pub(2)
|
||||||
|
|
||||||
if i != 3 {
|
if i != 3 {
|
||||||
t.Errorf("Expected i == 3, Got i == %d", i)
|
t.Errorf("Expected i == 3, Got i == %d", i)
|
||||||
}
|
}
|
||||||
|
if !ok {
|
||||||
|
t.Error("should return true When not reject. But got false.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestManyPub(t *testing.T) {
|
||||||
|
p := pfs.New()
|
||||||
|
i := 0
|
||||||
|
p.Sub(func(j int) {
|
||||||
|
i += j
|
||||||
|
})
|
||||||
|
|
||||||
|
for j := 0; j < 1000; j++ {
|
||||||
|
p.Pub(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if i != 1000 {
|
||||||
|
t.Errorf("i should be 1000, but got %d", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestManySub(t *testing.T) {
|
||||||
|
p := pfs.New()
|
||||||
|
i := 0
|
||||||
|
m := sync.Mutex{}
|
||||||
|
for j := 0; j < 1000; j++ {
|
||||||
|
p.Sub(func(j int) {
|
||||||
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
i += j
|
||||||
|
})
|
||||||
|
}
|
||||||
|
p.Pub(1)
|
||||||
|
if i != 1000 {
|
||||||
|
t.Errorf("i should be 1000, but got %d", i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSubWhenNotFunction(t *testing.T) {
|
func TestSubWhenNotFunction(t *testing.T) {
|
||||||
@ -71,3 +107,11 @@ func TestFilter(t *testing.T) {
|
|||||||
t.Error("should return false When reject. But got true.")
|
t.Error("should return false When reject. But got true.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilterWhenNotFunction(t *testing.T) {
|
||||||
|
pfs := pfs.New()
|
||||||
|
err := pfs.Filter("foobar")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("should return error When recieve not function. But got nil.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user