-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmessage_test.go
More file actions
80 lines (76 loc) · 1.6 KB
/
message_test.go
File metadata and controls
80 lines (76 loc) · 1.6 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package pgq
import (
"context"
"testing"
"time"
"go.dataddo.com/pgq/internal/require"
)
func TestMessageIncoming_LastAttempt(t *testing.T) {
type fields struct {
Attempt int
maxConsumedCount uint
}
tests := []struct {
name string
fields fields
want bool
}{
{
name: "maxConsumedCount is 0",
fields: fields{
maxConsumedCount: 0,
},
want: false,
},
{
name: "Attempt is less than maxConsumedCount",
fields: fields{
Attempt: 1,
maxConsumedCount: 2,
},
want: false,
},
{
name: "Attempt is equal to maxConsumedCount",
fields: fields{
Attempt: 2,
maxConsumedCount: 2,
},
want: true,
},
{
name: "Attempt is greater than maxConsumedCount",
fields: fields{
Attempt: 3,
maxConsumedCount: 2,
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &MessageIncoming{
Attempt: tt.fields.Attempt,
maxConsumedCount: tt.fields.maxConsumedCount,
}
if got := m.LastAttempt(); got != tt.want {
t.Errorf("LastAttempt() = %v, want %v", got, tt.want)
}
})
}
}
func TestMessageIncoming_SetDeadline(t *testing.T) {
m := &MessageIncoming{
Deadline: time.Date(9999, 0, 0, 0, 0, 0, 0, time.UTC),
updateLockedUntilFn: func(ctx context.Context, t time.Time) error {
return nil
},
}
ctx := context.Background()
ctx, err := m.SetDeadline(ctx, time.Now().Add(time.Second))
require.NoError(t, err)
ctx, err = m.SetDeadline(ctx, time.Now())
require.NoError(t, err)
ctx, err = m.SetDeadline(ctx, time.Now())
require.Error(t, err)
}