This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
server_test.go
74 lines (63 loc) · 1.72 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
63
64
65
66
67
68
69
70
71
72
73
74
package falconer
import (
"context"
"net"
"runtime"
"sync/atomic"
"testing"
"time"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/stripe/veneur/sinks/grpsink"
"github.com/stripe/veneur/ssf"
"google.golang.org/grpc"
)
func TestSpanIngest(t *testing.T) {
testaddr := "127.0.0.1:0"
lis, err := net.Listen("tcp", testaddr)
if err != nil {
t.Fatalf("Failed to set up net listener with err %s", err)
}
testaddr = lis.Addr().String()
cfg := Config{
Debug: true,
ListenAddress: testaddr,
SpanExpirationDurationSeconds: "60s",
WorkerCount: 1,
WorkerSpanDepth: 1,
WorkerWatchDepth: 1,
}
log := logrus.New()
falconerServer, err := NewServer(log, dummyTraceClient(), &cfg)
if err != nil {
log.WithError(err).Fatal("Failed to create server")
}
gsrv := grpc.NewServer()
grpsink.RegisterSpanSinkServer(gsrv, falconerServer)
go gsrv.Serve(lis)
runtime.Gosched()
conn, err := grpc.DialContext(context.Background(), testaddr, grpc.WithInsecure())
if err != nil {
t.Fatal(err)
}
start := time.Now()
end := start.Add(2 * time.Second)
testSpan := &ssf.SSFSpan{
TraceId: 1,
ParentId: 1,
Id: 2,
StartTimestamp: int64(start.UnixNano()),
EndTimestamp: int64(end.UnixNano()),
Error: false,
Service: "farts-srv",
Tags: map[string]string{
"baz": "qux",
},
Indicator: false,
Name: "farting farty farts",
}
client := grpsink.NewSpanSinkClient(conn)
client.SendSpan(context.Background(), testSpan)
// Check that our message has arrived on the other side
require.Equal(t, atomic.LoadUint64(&falconerServer.receivedCount), uint64(1))
}