github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/go-themis/oracle/oracles/local_test.go (about) 1 package oracles 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func TestLocalOracle(t *testing.T) { 9 l := NewLocalOracle() 10 m := map[uint64]struct{}{} 11 for i := 0; i < 100000; i++ { 12 ts, err := l.GetTimestamp() 13 if err != nil { 14 t.Error(err) 15 } 16 m[ts] = struct{}{} 17 } 18 19 if len(m) != 100000 { 20 t.Error("generated same ts") 21 } 22 } 23 24 func TestExpired(t *testing.T) { 25 o := NewLocalOracle() 26 ts, _ := o.GetTimestamp() 27 time.Sleep(1 * time.Second) 28 if !o.IsExpired(uint64(ts), 500) { 29 t.Error("should expired") 30 } 31 if o.IsExpired(uint64(ts), 2000) { 32 t.Error("should not expired") 33 } 34 }