Abstract out network part of TestRecord
@@ -28,12 +28,7 @@ func TestStartTrace(t *testing.T) {
assert.True(t, between)
}
-func TestRecord(t *testing.T) {
- const resource = "Robert'); DROP TABLE students;"
- const metricName = "veneur.trace.test"
- const serviceName = "veneur-test"
- Service = serviceName
-
+func testRecord(t *testing.T, trace *Trace, name string, tags map[string]string) (sample *ssf.SSFSpan, end time.Time) {
// arbitrary
const BufferSize = 1087152
@@ -41,6 +36,7 @@ func TestRecord(t *testing.T) {
assert.NoError(t, err)
serverConn, err := net.ListenUDP("udp", traceAddr)
assert.NoError(t, err)
+ defer serverConn.Close()
err = serverConn.SetReadBuffer(BufferSize)
assert.NoError(t, err)
@@ -62,6 +58,29 @@ func TestRecord(t *testing.T) {
kill <- struct{}{}
}()
+ trace.Record(name, tags)
+ end = time.Now()
+
+ select {
+ case _ = <-kill:
+ assert.Fail(t, "timed out waiting for socket read")
+ case resp := <-respChan:
+ // Because this is marshalled using protobuf,
+ // we can't expect the representation to be immutable
+ // and cannot test the marshalled payload directly
+ sample = &ssf.SSFSpan{}
+ err := proto.Unmarshal(resp, sample)
+ assert.NoError(t, err)
+ }
+ return
+}
+
+func TestRecord(t *testing.T) {
+ const resource = "Robert'); DROP TABLE students;"
+ const metricName = "veneur.trace.test"
+ const serviceName = "veneur-test"
+ Service = serviceName
+
trace := StartTrace(resource)
trace.Status = ssf.SSFSample_CRITICAL
trace.error = true
@@ -74,20 +93,7 @@ func TestRecord(t *testing.T) {
"name": metricName,
}
- trace.Record(metricName, tags)
- end := time.Now()
-
- select {
- case _ = <-kill:
- assert.Fail(t, "timed out waiting for socket read")
- case resp := <-respChan:
- // Because this is marshalled using protobuf,
- // we can't expect the representation to be immutable
- // and cannot test the marshalled payload directly
- sample := &ssf.SSFSpan{}
- err := proto.Unmarshal(resp, sample)
-
- assert.NoError(t, err)
+ sample, end := testRecord(t, trace, metricName, tags)
timestamp := time.Unix(sample.StartTimestamp/1e9, 0)
@@ -111,8 +117,6 @@ func TestRecord(t *testing.T) {
assert.Equal(t, tags, sample.Tags)
}
-}
-
func TestAttach(t *testing.T) {
const resource = "Robert'); DROP TABLE students;"
ctx := context.Background()
