The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/utils/singleton_test.go

41 lines
593 B

package utils
import (
"sync"
"testing"
"time"
)
var NumThreads = 20
func TestSingleton(t *testing.T) {
si := GetUniqueValidatorIDInstance()
var wg sync.WaitGroup
t.Log("unique ID provided by singleton instance")
for i := 0; i < NumThreads; i++ {
wg.Add(1)
go func() {
defer wg.Done()
t.Logf("id:%v\n", si.GetUniqueID())
time.Sleep(time.Millisecond)
}()
}
wg.Wait()
t.Log("non-unique ID")
n := 100
for i := 0; i < NumThreads; i++ {
wg.Add(1)
go func() {
defer wg.Done()
t.Log("num:", n)
n++
time.Sleep(time.Millisecond)
}()
}
wg.Wait()
}