(t *testing.T)
| 1698 | } |
| 1699 | |
| 1700 | func TestArchiveChatInterruptsActiveProcessing(t *testing.T) { |
| 1701 | t.Parallel() |
| 1702 | |
| 1703 | db, ps := dbtestutil.NewDB(t) |
| 1704 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1705 | |
| 1706 | streamStarted := make(chan struct{}) |
| 1707 | streamCanceled := make(chan struct{}) |
| 1708 | openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse { |
| 1709 | if !req.Stream { |
| 1710 | return chattest.OpenAINonStreamingResponse("title") |
| 1711 | } |
| 1712 | chunks := make(chan chattest.OpenAIChunk, 1) |
| 1713 | go func() { |
| 1714 | defer close(chunks) |
| 1715 | chunks <- chattest.OpenAITextChunks("partial")[0] |
| 1716 | select { |
| 1717 | case <-streamStarted: |
| 1718 | default: |
| 1719 | close(streamStarted) |
| 1720 | } |
| 1721 | <-req.Context().Done() |
| 1722 | select { |
| 1723 | case <-streamCanceled: |
| 1724 | default: |
| 1725 | close(streamCanceled) |
| 1726 | } |
| 1727 | }() |
| 1728 | return chattest.OpenAIResponse{StreamingChunks: chunks} |
| 1729 | }) |
| 1730 | |
| 1731 | server := newActiveTestServer(t, db, ps) |
| 1732 | user, org, model := seedChatDependencies(t, db) |
| 1733 | setOpenAIProviderBaseURL(ctx, t, db, openAIURL) |
| 1734 | |
| 1735 | chat, err := server.CreateChat(ctx, chatd.CreateOptions{ |
| 1736 | OwnerID: user.ID, |
| 1737 | OrganizationID: org.ID, |
| 1738 | Title: "archive-interrupt", |
| 1739 | ModelConfigID: model.ID, |
| 1740 | InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("hello")}, |
| 1741 | }) |
| 1742 | require.NoError(t, err) |
| 1743 | |
| 1744 | testutil.Eventually(ctx, t, func(ctx context.Context) bool { |
| 1745 | fromDB, dbErr := db.GetChatByID(ctx, chat.ID) |
| 1746 | if dbErr != nil { |
| 1747 | return false |
| 1748 | } |
| 1749 | return fromDB.Status == database.ChatStatusRunning && fromDB.WorkerID.Valid |
| 1750 | }, testutil.IntervalFast) |
| 1751 | |
| 1752 | testutil.Eventually(ctx, t, func(ctx context.Context) bool { |
| 1753 | select { |
| 1754 | case <-streamStarted: |
| 1755 | return true |
| 1756 | default: |
| 1757 | return false |
nothing calls this directly
no test coverage detected