-
-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathsleep_test.go
More file actions
31 lines (25 loc) · 597 Bytes
/
Copy pathsleep_test.go
File metadata and controls
31 lines (25 loc) · 597 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestNonInterruptedSleep(t *testing.T) {
t.Parallel()
err := interruptibleSleep(30*time.Millisecond, make(<-chan os.Signal))
assert.NoError(t, err)
}
func TestInterruptedSleep(t *testing.T) {
t.Parallel()
maxWait := 3 * time.Second
sigChan := make(chan os.Signal)
go func() {
time.Sleep(30 * time.Millisecond)
sigChan <- os.Interrupt
}()
start := time.Now()
err := interruptibleSleep(maxWait, sigChan)
assert.ErrorIs(t, err, errInterrupt)
assert.Less(t, time.Since(start), maxWait)
}