| 16 | ) |
| 17 | |
| 18 | func TestSubscribeProviderReload(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | |
| 21 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 22 | |
| 23 | logger := slogtest.Make(t, nil) |
| 24 | ps := dbpubsub.NewInMemory() |
| 25 | t.Cleanup(func() { _ = ps.Close() }) |
| 26 | |
| 27 | calls := &recordingReloader{} |
| 28 | |
| 29 | unsub, err := aibridged.SubscribeProviderReload(ctx, ps, calls, logger) |
| 30 | require.NoError(t, err) |
| 31 | t.Cleanup(unsub) |
| 32 | |
| 33 | require.Equal(t, 1, calls.count()) |
| 34 | |
| 35 | require.NoError(t, ps.Publish(pubsub.AIProvidersChangedChannel, nil)) |
| 36 | |
| 37 | require.Eventually(t, func() bool { return calls.count() >= 2 }, testutil.WaitShort, testutil.IntervalFast, |
| 38 | "Reload must fire again after a pubsub notification") |
| 39 | } |
| 40 | |
| 41 | func TestSubscribeProviderReloadSurfacesReloadError(t *testing.T) { |
| 42 | t.Parallel() |