-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtimed_test.go
51 lines (44 loc) · 1.23 KB
/
timed_test.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package goneli
import (
"sync"
"testing"
"time"
"github.com/obsidiandynamics/libstdgo/check"
"github.com/obsidiandynamics/libstdgo/scribe"
"github.com/stretchr/testify/require"
)
func TestPerformTimed_noError(t *testing.T) {
m := scribe.NewMock()
scr := scribe.New(m.Factories())
done, err := performTimed(scr.W(), "some-op", void(func() {}), 10*time.Second)
require.True(t, done)
require.Nil(t, err)
m.Entries().Assert(t, scribe.Count(0))
}
func TestPerformTimed_withError(t *testing.T) {
m := scribe.NewMock()
scr := scribe.New(m.Factories())
done, err := performTimed(scr.W(), "some-op", func() error {
return check.ErrSimulated
}, 10*time.Second)
require.True(t, done)
require.Equal(t, check.ErrSimulated, err)
m.Entries().Assert(t, scribe.Count(0))
}
func TestPerformTimed_withTimeout(t *testing.T) {
m := scribe.NewMock()
scr := scribe.New(m.Factories())
wg := sync.WaitGroup{}
wg.Add(1)
done, err := performTimed(scr.W(), "some-op", func() error {
wg.Wait()
return nil
}, 1*time.Millisecond)
require.False(t, done)
require.Nil(t, err)
m.Entries().
Having(scribe.LogLevel(scribe.Warn)).
Having(scribe.MessageEqual("Operation 'some-op' failed to complete within 1ms")).
Assert(t, scribe.Count(1))
wg.Done()
}