Skip to content

Commit 38340aa

Browse files
committed
chore: skip timing-sensistive AgentMetadata test in the standard suite
1 parent 501dfee commit 38340aa

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

agent/agent_test.go

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

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

10211056
dir := t.TempDir()

testutil/timing.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package testutil
2+
3+
import (
4+
"flag"
5+
"testing"
6+
)
7+
8+
// 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 humans manually running certain tests with the "-timing"
11+
// flag from time to time.
12+
//
13+
// Eventually, we should run all timing tests in a self-hosted runner.
14+
15+
var timingFlag = flag.Bool("timing", false, "run timing-sensitive tests")
16+
17+
func SkipIfNotTiming(t *testing.T) {
18+
if !*timingFlag {
19+
t.Skip("skipping timing-sensitive test")
20+
}
21+
}

0 commit comments

Comments
 (0)