1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-31 14:35:37 -05:00

aggressively close connection when response is done

This commit is contained in:
Darien Raymond
2017-09-27 15:29:00 +02:00
parent 2ce1d8ffa2
commit 109a37fe7e
8 changed files with 59 additions and 12 deletions

View File

@@ -0,0 +1,32 @@
package signal_test
import (
"context"
"runtime"
"testing"
"time"
. "v2ray.com/core/common/signal"
"v2ray.com/core/testing/assert"
)
func TestActivityTimer(t *testing.T) {
assert := assert.On(t)
ctx, timer := CancelAfterInactivity(context.Background(), time.Second*5)
time.Sleep(time.Second * 6)
assert.Error(ctx.Err()).IsNotNil()
runtime.KeepAlive(timer)
}
func TestActivityTimerUpdate(t *testing.T) {
assert := assert.On(t)
ctx, timer := CancelAfterInactivity(context.Background(), time.Second*10)
time.Sleep(time.Second * 3)
assert.Error(ctx.Err()).IsNil()
timer.SetTimeout(time.Second * 1)
time.Sleep(time.Second * 2)
assert.Error(ctx.Err()).IsNotNil()
runtime.KeepAlive(timer)
}