Skip to content

SpanCaptureReporter.collect returns spans from preceding tests #22

@garthk

Description

@garthk

I'm finding SpanCaptureReporter too brittle, with tests flaking out when :oc_reporter waits longer than expected and calls report/2 with spans from preceding tests after the current test calls attach/0.

Workaround:

defmodule MyApp.Module do
  use ExUnit.Case, async: false

  test "sends traces" do
    SpanCaptureReporter.attach()
    on_exit(make_ref(), &SpanCaptureReporter.detach/0)
    began_monotonic = :erlang.monotonic_time()
    
    # ... do the work ...

    spans =
    SpanCaptureReporter.collect()
    |> Enum.filter(fn span ->
        {native_time, _} = span.start_time
        native_time >= began_monotonic
    end)

    # ... check the spans ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions