1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-05-12 18:44:50 +00:00

Merge branch 'state-races' into state-copy

Test that races found in old code are no longer found in new code.
This commit is contained in:
Alex Bramley 2014-12-31 17:32:15 +00:00
commit c5830d598f
4 changed files with 74 additions and 5 deletions

View file

@ -1,6 +1,9 @@
package state
import "testing"
import (
"sync"
"testing"
)
// There is some awkwardness in these tests. Items retrieved directly from the
// state trackers internal maps are private and only have private,
@ -560,3 +563,56 @@ func TestSTWipe(t *testing.T) {
t.Errorf("Nick chan lists wrong length after wipe.")
}
}
func TestSTRaces(t *testing.T) {
st := NewTracker("mynick")
wg := sync.WaitGroup{}
for i := 'a'; i < 'g'; i++ {
wg.Add(2)
go func(s string) {
st.NewNick("nick-" + s)
c := st.NewChannel("#chan-" + s)
st.Associate(c, st.me)
wg.Done()
}(string(i))
go func(s string) {
n := st.GetNick("nick-" + s)
c := st.GetChannel("#chan-" + s)
st.Associate(c, n)
wg.Done()
}(string(i))
}
wg.Wait()
wg = sync.WaitGroup{}
race := func(ns, cs string) {
wg.Add(5)
go func() {
st.Associate(st.GetChannel("#chan-"+cs), st.GetNick("nick-"+ns))
wg.Done()
}()
go func() {
st.GetNick("nick-"+ns).Channels()
wg.Done()
}()
go func() {
st.GetChannel("#chan-"+cs).Nicks()
wg.Done()
}()
go func() {
st.Dissociate(st.GetChannel("#chan-"+cs), st.GetNick("nick-"+ns))
wg.Done()
}()
go func() {
st.ReNick("nick-"+ns, "nick2-"+ns)
wg.Done()
}()
}
for n := 'a'; n < 'g'; n++ {
for c := 'a'; c < 'g'; c++ {
race(string(n), string(c))
}
}
wg.Wait()
}