-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponders_test.go
More file actions
90 lines (69 loc) · 2.69 KB
/
responders_test.go
File metadata and controls
90 lines (69 loc) · 2.69 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
81
82
83
84
85
86
87
88
89
90
package platform
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestPublishResponder(t *testing.T) {
Convey("Ensure that the response sender uses the publisher", t, func() {
mockPublisher := newMockPublisher()
responder := NewPublishResponder(mockPublisher)
responder.Respond(&Request{
Routing: RouteToUri("resource:///teltech/reply/foobar"),
Completed: Bool(false),
})
// Wait for the response sender's goroutine
time.Sleep(10 * time.Millisecond)
So(len(mockPublisher.mockPublishes), ShouldEqual, 1)
responder.Respond(&Request{
Routing: RouteToUri("resource:///teltech/reply/foobar"),
Completed: Bool(true),
})
// Wait for the response sender's goroutine
time.Sleep(10 * time.Millisecond)
So(len(mockPublisher.mockPublishes), ShouldEqual, 2)
})
}
func TestRequestResponder(t *testing.T) {
Convey("Ensure that the response sender uses the publisher", t, func() {
mockPublisher := newMockPublisher()
requestResponder := NewRequestResponder(NewPublishResponder(mockPublisher), &Request{})
// Sending a response that is not completed should still produce heartbeats
requestResponder.Respond(&Request{
Routing: RouteToUri("resource:///teltech/reply/foobar"),
Completed: Bool(false),
})
// Let the goroutine send the message
time.Sleep(10 * time.Millisecond)
// Just by waiting for at least 500 milliseconds, we should see a heartbeat published
So(requestResponder.completed, ShouldBeFalse)
So(len(mockPublisher.mockPublishes), ShouldEqual, 1)
time.Sleep(750 * time.Millisecond)
So(requestResponder.completed, ShouldBeFalse)
So(len(mockPublisher.mockPublishes), ShouldEqual, 2)
// By sending a completed response, it should shut down the heartbeats
requestResponder.Respond(&Request{
Routing: RouteToUri("resource:///teltech/reply/foobar"),
Completed: Bool(true),
})
// Let the goroutine send the message
time.Sleep(10 * time.Millisecond)
So(requestResponder.completed, ShouldBeTrue)
So(len(mockPublisher.mockPublishes), ShouldEqual, 3)
time.Sleep(750 * time.Millisecond)
So(requestResponder.completed, ShouldBeTrue)
So(len(mockPublisher.mockPublishes), ShouldEqual, 3)
// Sending a response after last request was completed should do nothing
requestResponder.Respond(&Request{
Routing: RouteToUri("resource:///teltech/reply/foobar"),
Completed: Bool(true),
})
// Let the goroutine send the message
time.Sleep(10 * time.Millisecond)
So(requestResponder.completed, ShouldBeTrue)
So(len(mockPublisher.mockPublishes), ShouldEqual, 3)
time.Sleep(750 * time.Millisecond)
So(requestResponder.completed, ShouldBeTrue)
So(len(mockPublisher.mockPublishes), ShouldEqual, 3)
})
}