waitForChatProcessed waits for a wake-triggered processOnce to fully complete for the given chat. It polls until the chat leaves both pending and running states (meaning processChat has finished its cleanup and updated the DB), then calls WaitUntilIdleForTest. Waiting for a terminal state (not just
( ctx context.Context, t *testing.T, db database.Store, chatID uuid.UUID, server *chatd.Server, )
| 5764 | // waited for status != pending, we could call Wait() while Add(1) |
| 5765 | // hasn't happened yet. |
| 5766 | func waitForChatProcessed( |
| 5767 | ctx context.Context, |
| 5768 | t *testing.T, |
| 5769 | db database.Store, |
| 5770 | chatID uuid.UUID, |
| 5771 | server *chatd.Server, |
| 5772 | ) { |
| 5773 | t.Helper() |
| 5774 | require.Eventually(t, func() bool { |
| 5775 | c, err := db.GetChatByID(ctx, chatID) |
| 5776 | if err != nil { |
| 5777 | return false |
| 5778 | } |
| 5779 | // Wait until the chat reaches a terminal state. Neither |
| 5780 | // pending (waiting to be acquired) nor running (being |
| 5781 | // processed). This guarantees that inflight.Add(1) has |
| 5782 | // already been called by processOnce. |
| 5783 | return c.Status != database.ChatStatusPending && |
| 5784 | c.Status != database.ChatStatusRunning |
| 5785 | }, testutil.WaitShort, testutil.IntervalFast) |
| 5786 | chatd.WaitUntilIdleForTest(server) |
| 5787 | } |
| 5788 | |
| 5789 | // newTestServer creates a passive server that never calls |
| 5790 | // processOnce on its own. |
no test coverage detected