1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-29 02:35:23 +00:00
v2fly/common/protocol/server_spec_test.go

32 lines
651 B
Go
Raw Normal View History

2016-07-25 14:48:09 +00:00
package protocol_test
import (
"testing"
2016-07-25 19:31:16 +00:00
"time"
2016-07-25 14:48:09 +00:00
2016-08-20 18:55:45 +00:00
. "v2ray.com/core/common/protocol"
2017-10-24 14:15:35 +00:00
. "v2ray.com/ext/assert"
2016-07-25 14:48:09 +00:00
)
2016-07-25 19:31:16 +00:00
func TestAlwaysValidStrategy(t *testing.T) {
2017-10-24 14:15:35 +00:00
assert := With(t)
2016-07-25 19:31:16 +00:00
strategy := AlwaysValid()
2017-10-24 14:15:35 +00:00
assert(strategy.IsValid(), IsTrue)
2016-07-25 19:31:16 +00:00
strategy.Invalidate()
2017-10-24 14:15:35 +00:00
assert(strategy.IsValid(), IsTrue)
2016-07-25 19:31:16 +00:00
}
func TestTimeoutValidStrategy(t *testing.T) {
2017-10-24 14:15:35 +00:00
assert := With(t)
2016-07-25 19:31:16 +00:00
strategy := BeforeTime(time.Now().Add(2 * time.Second))
2017-10-24 14:15:35 +00:00
assert(strategy.IsValid(), IsTrue)
2016-07-25 19:31:16 +00:00
time.Sleep(3 * time.Second)
2017-10-24 14:15:35 +00:00
assert(strategy.IsValid(), IsFalse)
2016-07-25 19:31:16 +00:00
strategy = BeforeTime(time.Now().Add(2 * time.Second))
strategy.Invalidate()
2017-10-24 14:15:35 +00:00
assert(strategy.IsValid(), IsFalse)
2016-07-25 19:31:16 +00:00
}