-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathpublish_test.go
More file actions
47 lines (40 loc) · 1.17 KB
/
Copy pathpublish_test.go
File metadata and controls
47 lines (40 loc) · 1.17 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
package rabbitmq
import (
"errors"
"testing"
)
func TestPublisherRestartContinuesAfterError(t *testing.T) {
reconnectErrCh := make(chan error, 2)
reconnectErrCh <- errors.New("first reconnect")
reconnectErrCh <- errors.New("second reconnect")
close(reconnectErrCh)
publisher := &Publisher{
reconnectErrCh: reconnectErrCh,
options: PublisherOptions{
Logger: simpleLogF(t.Logf),
},
}
restarts := 0
publisher.restartOnReconnect(func() error {
restarts++
if restarts == 1 {
return errors.New("broker failed during exchange declaration")
}
return nil
})
if restarts != 2 {
t.Fatalf("restart attempts = %d, want 2", restarts)
}
}
func TestPublishFailsFastWhenPaused(t *testing.T) {
publisher := &Publisher{}
publisher.disablePublishDueToFlow.Store(true)
if err := publisher.Publish([]byte{}, []string{"key"}); !errors.Is(err, ErrPublishFlowPaused) {
t.Fatalf("err = %v, want ErrPublishFlowPaused", err)
}
publisher.disablePublishDueToFlow.Store(false)
publisher.disablePublishDueToBlocked.Store(true)
if err := publisher.Publish([]byte{}, []string{"key"}); !errors.Is(err, ErrPublishBlocked) {
t.Fatalf("err = %v, want ErrPublishBlocked", err)
}
}