mirror of https://github.com/v2ray/v2ray-core
More coverage
parent
33768175c1
commit
99f32f1dbf
|
@ -11,9 +11,9 @@ func TestTimedStringMap(t *testing.T) {
|
||||||
assert := unit.Assert(t)
|
assert := unit.Assert(t)
|
||||||
|
|
||||||
nowSec := time.Now().UTC().Unix()
|
nowSec := time.Now().UTC().Unix()
|
||||||
m := NewTimedStringMap(3)
|
m := NewTimedStringMap(2)
|
||||||
m.Set("Key1", "Value1", nowSec)
|
m.Set("Key1", "Value1", nowSec)
|
||||||
m.Set("Key2", "Value2", nowSec+20)
|
m.Set("Key2", "Value2", nowSec+5)
|
||||||
|
|
||||||
v1, ok := m.Get("Key1")
|
v1, ok := m.Get("Key1")
|
||||||
assert.Bool(ok).IsTrue()
|
assert.Bool(ok).IsTrue()
|
||||||
|
@ -23,7 +23,7 @@ func TestTimedStringMap(t *testing.T) {
|
||||||
assert.Bool(ok).IsTrue()
|
assert.Bool(ok).IsTrue()
|
||||||
assert.String(v2.(string)).Equals("Value2")
|
assert.String(v2.(string)).Equals("Value2")
|
||||||
|
|
||||||
tick := time.Tick(5 * time.Second)
|
tick := time.Tick(3 * time.Second)
|
||||||
<-tick
|
<-tick
|
||||||
|
|
||||||
v1, ok = m.Get("Key1")
|
v1, ok = m.Get("Key1")
|
||||||
|
@ -32,4 +32,17 @@ func TestTimedStringMap(t *testing.T) {
|
||||||
v2, ok = m.Get("Key2")
|
v2, ok = m.Get("Key2")
|
||||||
assert.Bool(ok).IsTrue()
|
assert.Bool(ok).IsTrue()
|
||||||
assert.String(v2.(string)).Equals("Value2")
|
assert.String(v2.(string)).Equals("Value2")
|
||||||
|
|
||||||
|
<-tick
|
||||||
|
v2, ok = m.Get("Key2")
|
||||||
|
assert.Bool(ok).IsFalse()
|
||||||
|
|
||||||
|
<-tick
|
||||||
|
v2, ok = m.Get("Key2")
|
||||||
|
assert.Bool(ok).IsFalse()
|
||||||
|
|
||||||
|
m.Set("Key1", "Value1", nowSec+10)
|
||||||
|
v1, ok = m.Get("Key1")
|
||||||
|
assert.Bool(ok).IsTrue()
|
||||||
|
assert.String(v1.(string)).Equals("Value1")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue