func TestZipkinTraceReporterFactory(t *testing.T) { ch, err := tchannel.NewChannel("svc", &tchannel.ChannelOptions{ TraceReporterFactory: ZipkinTraceReporterFactory, }) assert.NoError(t, err) // Create a TCollector channel, and add it as a peer to ch so Report works. mockServer := new(mocks.TChanTCollector) tcollectorCh, err := setupServer(mockServer) require.NoError(t, err, "setupServer failed") ch.Peers().Add(tcollectorCh.PeerInfo().HostPort) called := make(chan int) ret := &gen.Response{Ok: true} mockServer.On("Submit", mock.Anything, mock.Anything).Return(ret, nil).Run(func(args mock.Arguments) { called <- 1 }) // Make some calls, and validate that the trace reporter is not called recursively. require.NoError(t, json.Register(tcollectorCh, json.Handlers{"op": func(ctx json.Context, arg map[string]interface{}) (map[string]interface{}, error) { return arg, nil }}, nil), "Register failed") ctx, cancel := json.NewContext(time.Second) defer cancel() for i := 0; i < 5; i++ { var res map[string]string assert.NoError(t, json.CallSC(ctx, ch.GetSubChannel(tcollectorServiceName), "op", nil, &res), "call failed") } // Verify the spans being reported. for i := 0; i < 5; i++ { select { case <-called: case <-time.After(time.Second): t.Errorf("Expected submit for call %v", i) } } // Verify that no other spans are reported. select { case <-called: t.Errorf("Too many spans reported") case <-time.After(time.Millisecond): } }
func (c *Client) sendAdvertise() error { // Cannot advertise from an ephemeral peer. if c.tchan.PeerInfo().IsEphemeral() { return errEphemeralPeer } ctx, cancel := json.NewContext(c.opts.Timeout) defer cancel() // Disable tracing on Hyperbahn advertise messages to avoid cascading failures (see #790). tchannel.CurrentSpan(ctx).EnableTracing(false) sc := c.tchan.GetSubChannel(hyperbahnServiceName) arg := c.createRequest() var resp AdResponse c.opts.Handler.On(SendAdvertise) if err := json.CallSC(ctx, sc, "ad", arg, &resp); err != nil { return err } return nil }