Skip to content

Commit

Permalink
add tiny test start/end time validation (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel authored Jan 13, 2025
1 parent 63fcb37 commit 3833744
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions wasp/benchspy/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ func (b *BasicData) Validate() error {
return errors.New("test end time is missing. We cannot query Loki without a time range. Please set it and try again")
}

if b.TestEnd.Before(b.TestStart) {
return errors.New("test end time is before test start time. Please set valid times and try again")
}
if b.TestEnd.Sub(b.TestStart) < time.Second {
return errors.New("test duration is less than a second. Please set a valid time range and try again")
}

if len(b.GeneratorConfigs) == 0 {
return errors.New("generator configs are missing. At least one is required. Please set them and try again")
}
Expand Down
27 changes: 27 additions & 0 deletions wasp/benchspy/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,33 @@ func TestBenchSpy_TestBasicData_Validate(t *testing.T) {
wantErr: true,
errMsg: "generator configs are missing",
},
{
name: "test start and end time are the same",
bd: &BasicData{
TestStart: time.Now(),
TestEnd: time.Now(),
},
wantErr: true,
errMsg: "test duration is less than a second",
},
{
name: "test end time before start time",
bd: &BasicData{
TestStart: time.Now().Add(time.Hour),
TestEnd: time.Now(),
},
wantErr: true,
errMsg: "test end time is before test start time",
},
{
name: "test end time are start time < 1s apart",
bd: &BasicData{
TestStart: time.Now(),
TestEnd: time.Now().Add(time.Second - time.Millisecond),
},
wantErr: true,
errMsg: "test duration is less than a second",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 3833744

Please sign in to comment.