Beispiel #1
0
        public void should_forward_tracing_information_from_ocelot_and_downstream_services()
        {
            int port1         = RandomPortFinder.GetRandomPort();
            int port2         = RandomPortFinder.GetRandomPort();
            var configuration = new FileConfiguration()
            {
                ReRoutes = new List <FileReRoute>()
                {
                    new FileReRoute()
                    {
                        DownstreamPathTemplate = "/api/values",
                        DownstreamScheme       = "http",
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "localhost",
                                Port = port1,
                            }
                        },
                        UpstreamPathTemplate = "/api001/values",
                        UpstreamHttpMethod   = new List <string> {
                            "Get"
                        },
                        HttpHandlerOptions = new FileHttpHandlerOptions
                        {
                            UseTracing = true
                        }
                    },
                    new FileReRoute()
                    {
                        DownstreamPathTemplate = "/api/values",
                        DownstreamScheme       = "http",
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort()
                            {
                                Host = "localhost",
                                Port = port2,
                            }
                        },
                        UpstreamPathTemplate = "/api002/values",
                        UpstreamHttpMethod   = new List <string> {
                            "Get"
                        },
                        HttpHandlerOptions = new FileHttpHandlerOptions
                        {
                            UseTracing = true
                        }
                    }
                }
            };

            var tracingPort = RandomPortFinder.GetRandomPort();
            var tracingUrl  = $"http://localhost:{tracingPort}";

            var fakeTracer = new FakeTracer();

            this.Given(_ => GivenFakeOpenTracing(tracingUrl))
            .And(_ => GivenServiceOneIsRunning($"http://localhost:{port1}", "/api/values", 200, "Hello from Laura", tracingUrl))
            .And(_ => GivenServiceTwoIsRunning($"http://localhost:{port2}", "/api/values", 200, "Hello from Tom", tracingUrl))
            .And(_ => _steps.GivenThereIsAConfiguration(configuration))
            .And(_ => _steps.GivenOcelotIsRunningUsingOpenTracing(fakeTracer))
            .When(_ => _steps.WhenIGetUrlOnTheApiGateway("/api001/values"))
            .Then(_ => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(_ => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
            .When(_ => _steps.WhenIGetUrlOnTheApiGateway("/api002/values"))
            .Then(_ => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(_ => _steps.ThenTheResponseBodyShouldBe("Hello from Tom"))
            .BDDfy();

            var commandOnAllStateMachines = Wait.WaitFor(10000).Until(() => fakeTracer.BuildSpanCalled >= 2);

            _output.WriteLine($"fakeTracer.BuildSpanCalled is {fakeTracer.BuildSpanCalled}");

            commandOnAllStateMachines.ShouldBeTrue();
        }