@@ -413,7 +413,7 @@ func TestBenchSpy_StandardReport_UnmarshalJSON(t *testing.T) {
413413 assert .Equal (t , "1" , asStringSlice ["test generator query" ])
414414 })
415415
416- t .Run ("valid prometheus executor" , func (t * testing.T ) {
416+ t .Run ("valid prometheus executor (vector) " , func (t * testing.T ) {
417417 jsonData := `{
418418 "test_name": "test1",
419419 "commit_or_tag": "abc123",
@@ -819,3 +819,249 @@ func TestBenchSpy_ConvertQueryResults(t *testing.T) {
819819 })
820820 })
821821}
822+
823+ func TestBenchSpy_MustAllResults (t * testing.T ) {
824+ t .Run ("MustAllLokiResults" , func (t * testing.T ) {
825+ mockLokiExec := & MockQueryExecutor {
826+ ResultsFn : func () map [string ]interface {} {
827+ return map [string ]interface {}{
828+ "query1" : []string {"log1" , "log2" },
829+ "query2" : []string {"log3" , "log4" },
830+ }
831+ },
832+ KindFn : func () string {
833+ return string (StandardQueryExecutor_Loki )
834+ },
835+ }
836+
837+ sr := & StandardReport {
838+ QueryExecutors : []QueryExecutor {mockLokiExec },
839+ }
840+
841+ results := MustAllLokiResults (sr )
842+ assert .Equal (t , 2 , len (results ))
843+ assert .Equal (t , []string {"log1" , "log2" }, results ["query1" ])
844+ assert .Equal (t , []string {"log3" , "log4" }, results ["query2" ])
845+ })
846+
847+ t .Run ("MustAllGeneratorResults" , func (t * testing.T ) {
848+ mockGenExec := & MockQueryExecutor {
849+ ResultsFn : func () map [string ]interface {} {
850+ return map [string ]interface {}{
851+ "query1" : "result1" ,
852+ "query2" : "result2" ,
853+ }
854+ },
855+ KindFn : func () string {
856+ return string (StandardQueryExecutor_Generator )
857+ },
858+ }
859+
860+ sr := & StandardReport {
861+ QueryExecutors : []QueryExecutor {mockGenExec },
862+ }
863+
864+ results := MustAllGeneratorResults (sr )
865+ assert .Equal (t , 2 , len (results ))
866+ assert .Equal (t , "result1" , results ["query1" ])
867+ assert .Equal (t , "result2" , results ["query2" ])
868+ })
869+
870+ t .Run ("MustAllPrometheusResults" , func (t * testing.T ) {
871+ vector1 := model.Vector {
872+ & model.Sample {
873+ Value : 1.23 ,
874+ },
875+ }
876+ vector2 := model.Vector {
877+ & model.Sample {
878+ Value : 4.56 ,
879+ },
880+ }
881+
882+ mockPromExec := & MockQueryExecutor {
883+ ResultsFn : func () map [string ]interface {} {
884+ return map [string ]interface {}{
885+ "query1" : vector1 ,
886+ "query2" : vector2 ,
887+ }
888+ },
889+ KindFn : func () string {
890+ return string (StandardQueryExecutor_Prometheus )
891+ },
892+ }
893+
894+ sr := & StandardReport {
895+ QueryExecutors : []QueryExecutor {mockPromExec },
896+ }
897+
898+ results := MustAllPrometheusResults (sr )
899+ assert .Equal (t , 2 , len (results ))
900+ assert .Equal (t , model .Vector (vector1 ), results ["query1" ].(model.Vector ))
901+ assert .Equal (t , model .Vector (vector2 ), results ["query2" ].(model.Vector ))
902+ })
903+
904+ t .Run ("MustAllLokiResults panics on wrong type" , func (t * testing.T ) {
905+ mockExec := & MockQueryExecutor {
906+ ResultsFn : func () map [string ]interface {} {
907+ return map [string ]interface {}{
908+ "query1" : 123 , // wrong type
909+ }
910+ },
911+ KindFn : func () string {
912+ return string (StandardQueryExecutor_Loki )
913+ },
914+ }
915+
916+ sr := & StandardReport {
917+ QueryExecutors : []QueryExecutor {mockExec },
918+ }
919+
920+ assert .Panics (t , func () {
921+ MustAllLokiResults (sr )
922+ })
923+ })
924+
925+ t .Run ("MustAllGeneratorResults panics on wrong type" , func (t * testing.T ) {
926+ mockExec := & MockQueryExecutor {
927+ ResultsFn : func () map [string ]interface {} {
928+ return map [string ]interface {}{
929+ "query1" : []string {"wrong" , "type" },
930+ }
931+ },
932+ KindFn : func () string {
933+ return string (StandardQueryExecutor_Generator )
934+ },
935+ }
936+
937+ sr := & StandardReport {
938+ QueryExecutors : []QueryExecutor {mockExec },
939+ }
940+
941+ assert .Panics (t , func () {
942+ MustAllGeneratorResults (sr )
943+ })
944+ })
945+
946+ t .Run ("Results from mixed executors" , func (t * testing.T ) {
947+ mockLokiExec := & MockQueryExecutor {
948+ ResultsFn : func () map [string ]interface {} {
949+ return map [string ]interface {}{
950+ "loki_query" : []string {"log1" , "log2" },
951+ }
952+ },
953+ KindFn : func () string {
954+ return string (StandardQueryExecutor_Loki )
955+ },
956+ }
957+
958+ mockGenExec := & MockQueryExecutor {
959+ ResultsFn : func () map [string ]interface {} {
960+ return map [string ]interface {}{
961+ "gen_query" : "result1" ,
962+ }
963+ },
964+ KindFn : func () string {
965+ return string (StandardQueryExecutor_Generator )
966+ },
967+ }
968+
969+ sr := & StandardReport {
970+ QueryExecutors : []QueryExecutor {mockLokiExec , mockGenExec },
971+ }
972+
973+ lokiResults := MustAllLokiResults (sr )
974+ assert .Equal (t , 1 , len (lokiResults ))
975+ assert .Equal (t , []string {"log1" , "log2" }, lokiResults ["loki_query" ])
976+
977+ genResults := MustAllGeneratorResults (sr )
978+ assert .Equal (t , 1 , len (genResults ))
979+ assert .Equal (t , "result1" , genResults ["gen_query" ])
980+ })
981+ }
982+
983+ func TestBenchSpy_FetchNewReportAndLoadLatestPrevious (t * testing.T ) {
984+ baseTime := time .Now ()
985+ basicGen := & wasp.Generator {
986+ Cfg : & wasp.Config {
987+ T : t ,
988+ GenName : "test-gen" ,
989+ Labels : map [string ]string {
990+ "branch" : "main" ,
991+ "commit" : "abc123" ,
992+ },
993+ Schedule : []* wasp.Segment {
994+ {StartTime : baseTime , EndTime : baseTime .Add (time .Hour ), From : 1 , Duration : 2 * time .Second },
995+ },
996+ LokiConfig : lokiConfig ,
997+ },
998+ }
999+
1000+ t .Run ("successful execution" , func (t * testing.T ) {
1001+ tmpDir := t .TempDir ()
1002+
1003+ cfg := & wasp.Config {
1004+ T : t ,
1005+ LoadType : wasp .RPS ,
1006+ GenName : "test-gen" ,
1007+ Labels : map [string ]string {
1008+ "branch" : "main" ,
1009+ "commit" : "abc123" ,
1010+ },
1011+ Schedule : []* wasp.Segment {
1012+ {StartTime : baseTime , EndTime : baseTime .Add (time .Hour ), From : 1 , Duration : 2 * time .Second , Type : wasp .SegmentType_Plain },
1013+ },
1014+ }
1015+
1016+ fakeGun := & fakeGun {
1017+ maxSuccesses : 4 ,
1018+ maxFailures : 3 ,
1019+ schedule : cfg .Schedule [0 ],
1020+ }
1021+
1022+ cfg .Gun = fakeGun
1023+
1024+ gen , err := wasp .NewGenerator (cfg )
1025+ require .NoError (t , err )
1026+
1027+ gen .Run (true )
1028+
1029+ prevReport , err := NewStandardReport ("a7fc5826a572c09f8b93df3b9f674113372ce924" ,
1030+ WithStandardQueryExecutorType (StandardQueryExecutor_Generator ),
1031+ WithGenerators (gen ),
1032+ WithReportDirectory (tmpDir ))
1033+ require .NoError (t , err )
1034+ _ , err = prevReport .Store ()
1035+ require .NoError (t , err )
1036+
1037+ newReport , prevLoadedReport , err := FetchNewReportAndLoadLatestPrevious (
1038+ context .Background (),
1039+ "new-commit" ,
1040+ WithStandardQueryExecutorType (StandardQueryExecutor_Generator ),
1041+ WithGenerators (gen ),
1042+ WithReportDirectory (tmpDir ),
1043+ )
1044+ require .NoError (t , err )
1045+
1046+ assert .NotNil (t , newReport )
1047+ assert .NotNil (t , prevLoadedReport )
1048+ assert .Equal (t , "a7fc5826a572c09f8b93df3b9f674113372ce924" , prevLoadedReport .CommitOrTag )
1049+ })
1050+
1051+ t .Run ("no previous report" , func (t * testing.T ) {
1052+ tmpDir := t .TempDir ()
1053+
1054+ basicGen .Cfg .T = t
1055+ newReport , prevReport , err := FetchNewReportAndLoadLatestPrevious (
1056+ context .Background (),
1057+ "new-commit-7" ,
1058+ WithStandardQueryExecutorType (StandardQueryExecutor_Generator ),
1059+ WithGenerators (basicGen ),
1060+ WithReportDirectory (tmpDir ),
1061+ )
1062+
1063+ assert .Error (t , err )
1064+ assert .Nil (t , newReport )
1065+ assert .Nil (t , prevReport )
1066+ })
1067+ }
0 commit comments