Browse Source

test case for 0 timeout

Darien Raymond 7 năm trước cách đây
mục cha
commit
d6513ee4ec
2 tập tin đã thay đổi với 10 bổ sung0 xóa
  1. 1 0
      common/signal/timer.go
  2. 9 0
      common/signal/timer_test.go

+ 1 - 0
common/signal/timer.go

@@ -42,6 +42,7 @@ func (t *ActivityTimer) finish() {
 
 	if t.onTimeout != nil {
 		t.onTimeout()
+		t.onTimeout = nil
 	}
 	if t.checkTask != nil {
 		t.checkTask.Close() // nolint: errcheck

+ 9 - 0
common/signal/timer_test.go

@@ -44,3 +44,12 @@ func TestActivityTimerNonBlocking(t *testing.T) {
 	timer.SetTimeout(1)
 	timer.SetTimeout(2)
 }
+
+func TestActivityTimerZeroTimeout(t *testing.T) {
+	assert := With(t)
+
+	ctx, cancel := context.WithCancel(context.Background())
+	timer := CancelAfterInactivity(ctx, cancel, 0)
+	assert(ctx, HasDone)
+	runtime.KeepAlive(timer)
+}