package perftiming

import (
	"context"
	"testing"
)

func TestObserverIsOptInAndProcessLocal(t *testing.T) {
	if started := StartObservation(context.Background()); !started.IsZero() {
		t.Fatal("observation clock started without an observer")
	}

	var got Observation
	ctx := WithObserver(context.Background(), ObserverFunc(func(observation Observation) {
		got = observation
	}))
	started := StartObservation(ctx)
	if started.IsZero() {
		t.Fatal("observation clock did not start")
	}
	Observe(ctx, "selected_root.test", started)
	if got.Name != "selected_root.test" || got.Duration < 0 {
		t.Fatalf("observation = %#v", got)
	}
}
