diff --git a/backtester/engine/backtest_test.go b/backtester/engine/backtest_test.go index 326c8ef6..ecf89c74 100644 --- a/backtester/engine/backtest_test.go +++ b/backtester/engine/backtest_test.go @@ -1641,6 +1641,10 @@ func TestExecuteStrategy(t *testing.T) { err = bt.ExecuteStrategy(false) require.NoError(t, err) + // Wait for the async goroutine to complete before proceeding + // to avoid race condition where Stop() is called after we reset metadata + require.Eventually(t, bt.HasRan, time.Second, 10*time.Millisecond, "async goroutine must complete") + bt.m.Lock() bt.MetaData.LiveTesting = true bt.MetaData.DateStarted = time.Time{}