Skip to content

Commit 68d1ef7

Browse files
committed
chore: skip timing-sensistive AgentMetadata test in the standard suite
1 parent 2b9d128 commit 68d1ef7

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

agent/agent_test.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,46 @@ func TestAgent_Metadata(t *testing.T) {
10081008
})
10091009

10101010
t.Run("Many", func(t *testing.T) {
1011+
t.Parallel()
1012+
script := "echo -n hello"
1013+
if runtime.GOOS == "windows" {
1014+
script = "powershell " + script
1015+
}
1016+
//nolint:dogsled
1017+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
1018+
Metadata: []codersdk.WorkspaceAgentMetadataDescription{
1019+
{
1020+
Key: "greeting",
1021+
Interval: 1,
1022+
Script: script,
1023+
},
1024+
},
1025+
}, 0)
1026+
1027+
var gotMd map[string]agentsdk.PostMetadataRequest
1028+
require.Eventually(t, func() bool {
1029+
gotMd = client.getMetadata()
1030+
return len(gotMd) == 1
1031+
}, testutil.WaitShort, testutil.IntervalMedium)
1032+
1033+
collectedAt1 := gotMd["greeting"].CollectedAt
1034+
assert.Equal(t, "hello", gotMd["greeting"].Value)
1035+
1036+
if !assert.Eventually(t, func() bool {
1037+
gotMd = client.getMetadata()
1038+
return gotMd["greeting"].CollectedAt.After(collectedAt1)
1039+
}, testutil.WaitShort, testutil.IntervalMedium) {
1040+
t.Fatalf("expected metadata to be collected again")
1041+
}
1042+
})
1043+
1044+
t.Run("ManyTiming", func(t *testing.T) {
10111045
if runtime.GOOS == "windows" {
10121046
// Shell scripting in Windows is a pain, and we have already tested
1013-
// that the OS logic works in the simpler "Once" test above.
1047+
// that the OS logic works in the simpler tests.
10141048
t.Skip()
10151049
}
1050+
testutil.SkipIfNotTiming(t)
10161051
t.Parallel()
10171052

10181053
dir := t.TempDir()

testutil/timing.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package testutil
2+
3+
import (
4+
"flag"
5+
"testing"
6+
)
7+
8+
// For the time-being, we can't run timing-sensitive tests in CI because of the
9+
// great variance in runner performance. Instead of not testing timing at all,
10+
// we relegate it to the human to manually run the timing test on a
11+
// consistent machine from time to time.
12+
13+
var timingFlag = flag.Bool("timing", false, "run timing-sensitive tests")
14+
15+
func SkipIfNotTiming(t *testing.T) {
16+
if !*timingFlag {
17+
t.Skip("skipping timing-sensitive test")
18+
}
19+
}

0 commit comments

Comments
 (0)