MCPcopy Create free account
hub / github.com/coder/coder / TestWaitingChatsAreNotRecoveredAsStale

Function TestWaitingChatsAreNotRecoveredAsStale

coderd/x/chatd/chatd_test.go:3889–3931  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3887}
3888
3889func TestWaitingChatsAreNotRecoveredAsStale(t *testing.T) {
3890 t.Parallel()
3891
3892 db, ps := dbtestutil.NewDB(t)
3893
3894 ctx := testutil.Context(t, testutil.WaitLong)
3895 user, org, model := seedChatDependencies(t, db)
3896
3897 // Create a chat in waiting status. This should NOT be touched
3898 // by stale recovery.
3899 chat := dbgen.Chat(t, db, database.Chat{
3900 OrganizationID: org.ID,
3901 OwnerID: user.ID,
3902 Title: "waiting-chat",
3903 LastModelConfigID: model.ID,
3904 })
3905
3906 // Start a replica with a short stale threshold.
3907 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
3908 server := chatd.New(chatd.Config{
3909 Logger: logger,
3910 Database: db,
3911 ReplicaID: uuid.New(),
3912 Pubsub: ps,
3913 PendingChatAcquireInterval: testutil.WaitLong,
3914 InFlightChatStaleAfter: 500 * time.Millisecond,
3915 })
3916 server.Start()
3917 t.Cleanup(func() {
3918 require.NoError(t, server.Close())
3919 })
3920
3921 // Wait long enough for multiple periodic recovery cycles to
3922 // run (staleAfter/5 = 100ms intervals).
3923 require.Never(t, func() bool {
3924 fromDB, err := db.GetChatByID(ctx, chat.ID)
3925 if err != nil {
3926 return false
3927 }
3928 return fromDB.Status != database.ChatStatusWaiting
3929 }, time.Second, testutil.IntervalFast,
3930 "waiting chat should not be modified by stale recovery")
3931}
3932
3933func TestUpdateChatStatusPersistsLastError(t *testing.T) {
3934 t.Parallel()

Callers

nothing calls this directly

Calls 10

NewDBFunction · 0.92
ContextFunction · 0.92
ChatFunction · 0.92
NewFunction · 0.92
seedChatDependenciesFunction · 0.70
NewMethod · 0.65
StartMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65
GetChatByIDMethod · 0.65

Tested by

no test coverage detected