@@ -928,6 +928,96 @@ func TestUpdateJob(t *testing.T) {
928
928
require .Equal (t , workspaceTags [1 ].Key , "cat" )
929
929
require .Equal (t , workspaceTags [1 ].Value , "jinx" )
930
930
})
931
+
932
+ t .Run ("LogSizeLimit" , func (t * testing.T ) {
933
+ t .Parallel ()
934
+ srv , db , _ , pd := setup (t , false , & overrides {})
935
+ job := setupJob (t , db , pd .ID , pd .Tags )
936
+
937
+ // Create a log message that exceeds the 1MB limit
938
+ largeOutput := strings .Repeat ("a" , 1048577 ) // 1MB + 1 byte
939
+
940
+ _ , err := srv .UpdateJob (ctx , & proto.UpdateJobRequest {
941
+ JobId : job .String (),
942
+ Logs : []* proto.Log {{
943
+ Source : proto .LogSource_PROVISIONER ,
944
+ Level : sdkproto .LogLevel_INFO ,
945
+ Output : largeOutput ,
946
+ }},
947
+ })
948
+ require .NoError (t , err ) // Should succeed but trigger overflow
949
+
950
+ // Verify the overflow flag is set
951
+ jobResult , err := db .GetProvisionerJobByID (ctx , job )
952
+ require .NoError (t , err )
953
+ require .True (t , jobResult .LogsOverflowed )
954
+ })
955
+
956
+ t .Run ("IncrementalLogSizeOverflow" , func (t * testing.T ) {
957
+ t .Parallel ()
958
+ srv , db , _ , pd := setup (t , false , & overrides {})
959
+ job := setupJob (t , db , pd .ID , pd .Tags )
960
+
961
+ // Send logs that together exceed the limit
962
+ mediumOutput := strings .Repeat ("b" , 524289 ) // Half a MB + 1 byte
963
+
964
+ // First log - should succeed
965
+ _ , err := srv .UpdateJob (ctx , & proto.UpdateJobRequest {
966
+ JobId : job .String (),
967
+ Logs : []* proto.Log {{
968
+ Source : proto .LogSource_PROVISIONER ,
969
+ Level : sdkproto .LogLevel_INFO ,
970
+ Output : mediumOutput ,
971
+ }},
972
+ })
973
+ require .NoError (t , err )
974
+
975
+ // Verify overflow flag not yet set
976
+ jobResult , err := db .GetProvisionerJobByID (ctx , job )
977
+ require .NoError (t , err )
978
+ require .False (t , jobResult .LogsOverflowed )
979
+
980
+ // Second log - should trigger overflow
981
+ _ , err = srv .UpdateJob (ctx , & proto.UpdateJobRequest {
982
+ JobId : job .String (),
983
+ Logs : []* proto.Log {{
984
+ Source : proto .LogSource_PROVISIONER ,
985
+ Level : sdkproto .LogLevel_INFO ,
986
+ Output : mediumOutput ,
987
+ }},
988
+ })
989
+ require .NoError (t , err )
990
+
991
+ // Verify overflow flag is set
992
+ jobResult , err = db .GetProvisionerJobByID (ctx , job )
993
+ require .NoError (t , err )
994
+ require .True (t , jobResult .LogsOverflowed )
995
+ })
996
+
997
+ t .Run ("LogSizeTracking" , func (t * testing.T ) {
998
+ t .Parallel ()
999
+ srv , db , _ , pd := setup (t , false , & overrides {})
1000
+ job := setupJob (t , db , pd .ID , pd .Tags )
1001
+
1002
+ logOutput := "test log message"
1003
+ expectedSize := int32 (len (logOutput ))
1004
+
1005
+ _ , err := srv .UpdateJob (ctx , & proto.UpdateJobRequest {
1006
+ JobId : job .String (),
1007
+ Logs : []* proto.Log {{
1008
+ Source : proto .LogSource_PROVISIONER ,
1009
+ Level : sdkproto .LogLevel_INFO ,
1010
+ Output : logOutput ,
1011
+ }},
1012
+ })
1013
+ require .NoError (t , err )
1014
+
1015
+ // Verify the logs_length is correctly tracked
1016
+ jobResult , err := db .GetProvisionerJobByID (ctx , job )
1017
+ require .NoError (t , err )
1018
+ require .Equal (t , expectedSize , jobResult .LogsLength )
1019
+ require .False (t , jobResult .LogsOverflowed )
1020
+ })
931
1021
}
932
1022
933
1023
func TestFailJob (t * testing.T ) {
0 commit comments