-
Notifications
You must be signed in to change notification settings - Fork 41
/
server_test.go
62 lines (58 loc) · 1.9 KB
/
server_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
52
53
54
55
56
57
58
59
60
61
62
package signalr
import (
"context"
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Server.HubClients", func() {
Context("All().Send()", func() {
j := 1
It(fmt.Sprintf("should send clients %v", j), func(done Done) {
// Create a simple server
server, err := NewServer(context.TODO(), SimpleHubFactory(&simpleHub{}),
testLoggerOption(),
ChanReceiveTimeout(200*time.Millisecond),
StreamBufferCapacity(5))
Expect(err).NotTo(HaveOccurred())
Expect(server).NotTo(BeNil())
// Create both ends of the connection
cliConn, srvConn := newClientServerConnections()
// Start the server
go func() { _ = server.Serve(srvConn) }()
// Give the server some time. In contrast to the client, we have not connected state to query
<-time.After(100 * time.Millisecond)
// Create the Client
receiver := &simpleReceiver{ch: make(chan string, 1)}
ctx, cancelClient := context.WithCancel(context.Background())
client, _ := NewClient(ctx,
WithConnection(cliConn),
WithReceiver(receiver),
testLoggerOption(),
TransferFormat("Text"))
Expect(client).NotTo(BeNil())
// Start it
client.Start()
// Wait for client running
Expect(<-client.WaitForState(context.Background(), ClientConnected)).NotTo(HaveOccurred())
// Send from the server to "all" clients
<-time.After(100 * time.Millisecond)
server.HubClients().All().Send("OnCallback", fmt.Sprintf("All%v", j))
// Did the receiver get what we did send?
Expect(<-receiver.ch).To(Equal(fmt.Sprintf("All%v", j)))
cancelClient()
server.cancel()
close(done)
}, 1.0)
})
Context("Caller()", func() {
It("should return nil", func() {
server, _ := NewServer(context.TODO(), SimpleHubFactory(&simpleHub{}),
testLoggerOption(),
ChanReceiveTimeout(200*time.Millisecond),
StreamBufferCapacity(5))
Expect(server.HubClients().Caller()).To(BeNil())
})
})
})