@@ -869,9 +869,43 @@ func TestAgent_StartupScript(t *testing.T) {
869
869
func TestAgent_Metadata (t * testing.T ) {
870
870
t .Parallel ()
871
871
872
- t .Run ("Basic" , func (t * testing.T ) {
872
+ t .Run ("Once" , func (t * testing.T ) {
873
+ t .Parallel ()
874
+ script := "echo -n hello"
875
+ if runtime .GOOS == "windows" {
876
+ script = "powershell " + script
877
+ }
878
+ //nolint:dogsled
879
+ _ , client , _ , _ , _ := setupAgent (t , agentsdk.Manifest {
880
+ Metadata : []codersdk.WorkspaceAgentMetadataDescription {
881
+ {
882
+ Key : "greeting" ,
883
+ Interval : 0 ,
884
+ Script : script ,
885
+ },
886
+ },
887
+ }, 0 )
888
+
889
+ var gotMd map [string ]agentsdk.PostMetadataRequest
890
+ require .Eventually (t , func () bool {
891
+ gotMd = client .getMetadata ()
892
+ return len (gotMd ) == 1
893
+ }, testutil .WaitShort , testutil .IntervalMedium )
894
+
895
+ collectedAt := gotMd ["greeting" ].CollectedAt
896
+
897
+ require .Never (t , func () bool {
898
+ gotMd = client .getMetadata ()
899
+ if len (gotMd ) != 1 {
900
+ panic ("unexpected number of metadata" )
901
+ }
902
+ return ! gotMd ["greeting" ].CollectedAt .Equal (collectedAt )
903
+ }, testutil .WaitShort , testutil .IntervalMedium )
904
+ })
905
+
906
+ t .Run ("Many" , func (t * testing.T ) {
873
907
if runtime .GOOS == "windows" {
874
- // Shell scripting in Windows is a pain, so but we test that it works in the simpler "CollectOnce"
908
+ // Shell scripting in Windows is a pain, but we test that it works in the simpler "CollectOnce"
875
909
// test.
876
910
t .Skip ()
877
911
}
@@ -906,8 +940,7 @@ func TestAgent_Metadata(t *testing.T) {
906
940
panic ("unexpected number of metadata entries" )
907
941
}
908
942
909
- // Trim space to be OS-newline agnostic.
910
- require .Equal (t , "hello" , strings .TrimSpace (md ["greeting" ].Value ))
943
+ require .Equal (t , "hello\n " , md ["greeting" ].Value )
911
944
require .Equal (t , "exit status 1" , md ["bad" ].Error )
912
945
913
946
greetingByt , err := os .ReadFile (greetingPath )
@@ -920,7 +953,7 @@ func TestAgent_Metadata(t *testing.T) {
920
953
lowerBound = (int (idealNumGreetings ) / 2 )
921
954
)
922
955
923
- if idealNumGreetings < 5 {
956
+ if idealNumGreetings < 10 {
924
957
// Not enough time has passed to get a good sample size.
925
958
continue
926
959
}
@@ -936,39 +969,6 @@ func TestAgent_Metadata(t *testing.T) {
936
969
}
937
970
})
938
971
939
- t .Run ("CollectOnce" , func (t * testing.T ) {
940
- t .Parallel ()
941
- script := "echo -n hello"
942
- if runtime .GOOS == "windows" {
943
- script = "powershell " + script
944
- }
945
- //nolint:dogsled
946
- _ , client , _ , _ , _ := setupAgent (t , agentsdk.Manifest {
947
- Metadata : []codersdk.WorkspaceAgentMetadataDescription {
948
- {
949
- Key : "greeting" ,
950
- Interval : 0 ,
951
- Script : script ,
952
- },
953
- },
954
- }, 0 )
955
-
956
- var gotMd map [string ]agentsdk.PostMetadataRequest
957
- require .Eventually (t , func () bool {
958
- gotMd = client .getMetadata ()
959
- return len (gotMd ) == 1
960
- }, testutil .WaitShort , testutil .IntervalMedium )
961
-
962
- collectedAt := gotMd ["greeting" ].CollectedAt
963
-
964
- require .Never (t , func () bool {
965
- gotMd = client .getMetadata ()
966
- if len (gotMd ) != 1 {
967
- panic ("unexpected number of metadata" )
968
- }
969
- return ! gotMd ["greeting" ].CollectedAt .Equal (collectedAt )
970
- }, testutil .WaitShort , testutil .IntervalMedium )
971
- })
972
972
}
973
973
974
974
func TestAgent_Lifecycle (t * testing.T ) {
0 commit comments