MCPcopy Index your code
hub / github.com/coder/coder / TestFallbackPollTriggersScan

Function TestFallbackPollTriggersScan

agent/agentgit/agentgit_test.go:917–949  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

915}
916
917func TestFallbackPollTriggersScan(t *testing.T) {
918 t.Parallel()
919
920 ctx := testutil.Context(t, testutil.WaitLong)
921 repoDir := initTestRepo(t)
922 mClock := quartz.NewMock(t)
923
924 ps := agentgit.NewPathStore()
925 chatID := uuid.New()
926
927 require.NoError(t, os.WriteFile(filepath.Join(repoDir, "poll.go"), []byte("package poll\n"), 0o600))
928 ps.AddPaths([]uuid.UUID{chatID}, []string{filepath.Join(repoDir, "poll.go")})
929
930 // Only the fallback poll can trigger scans (no filesystem
931 // watcher).
932 stream := dialGitWatchWithPathStore(t, ps, chatID, agentgit.WithClock(mClock))
933 ch := stream.Chan()
934
935 // We should get an initial scan from subscribe.
936 msg1 := recvMsg(ctx, t, ch)
937 require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg1.Type)
938
939 // Add a new dirty file so the next scan has a delta to report.
940 require.NoError(t, os.WriteFile(filepath.Join(repoDir, "poll2.go"), []byte("package poll\n"), 0o600))
941
942 // Advance to the fallback poll interval. This should trigger a
943 // scan without any explicit refresh.
944 mClock.Advance(5 * time.Second).MustWait(context.Background())
945
946 msg2 := recvMsg(ctx, t, ch)
947 require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg2.Type)
948 require.NotEmpty(t, msg2.Repositories)
949}
950
951func TestMultipleConcurrentConnections(t *testing.T) {
952 t.Parallel()

Callers

nothing calls this directly

Calls 12

AddPathsMethod · 0.95
ContextFunction · 0.92
NewPathStoreFunction · 0.92
WithClockFunction · 0.92
initTestRepoFunction · 0.85
recvMsgFunction · 0.85
NotEmptyMethod · 0.80
NewMethod · 0.65
WriteFileMethod · 0.65
ChanMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected