Skip to content

Commit

Permalink
ensure *taskMetadata type returned from GetTaskMetadataProvider has a…
Browse files Browse the repository at this point in the history
… stable interface going forward
  • Loading branch information
josephcopenhaver committed Aug 16, 2024
1 parent 186b9e3 commit 39c3cf5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
12 changes: 0 additions & 12 deletions loadtester/task_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ func injectTaskMetadataProvider(ctx context.Context, tm *taskMetadata) context.C
return context.WithValue(ctx, taskMetadataCtxKey{}, tm)
}

type taskMetadataProvider interface {
IntervalID() time.Time
EnqueueTime() time.Time
DequeueTime() time.Time
SampleSize() int
NumIntervalTasks() int
Lag() time.Duration
}

// TODO: move to unit test
var _ taskMetadataProvider = (*taskMetadata)(nil)

// GetTaskMetadataProvider returns a possibly nil value that implements:
//
// - `IntervalID() time.Time`
Expand Down
53 changes: 53 additions & 0 deletions loadtester/task_metadata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package loadtester

import (
"testing"
"time"
)

func TestMetadataProviderInterfaceStability(t *testing.T) {
type taskMetadataProvider interface {
IntervalID() time.Time
EnqueueTime() time.Time
DequeueTime() time.Time
SampleSize() int
NumIntervalTasks() int
Lag() time.Duration
}

now := time.Now()
v := taskMetadataProvider(&taskMetadata{taskMetadataState{
meta: taskMeta{
IntervalID: now,
SampleSize: 2,
NumIntervalTasks: 3,
Lag: 2 * time.Second,
},
enqueueTime: now.Add(1 * time.Minute),
dequeueTime: now.Add(2 * time.Minute),
}})

if !v.IntervalID().Equal(now) {
t.Fatal()
}

if !v.EnqueueTime().Equal(now.Add(1 * time.Minute)) {
t.Fatal()
}

if !v.DequeueTime().Equal(now.Add(2 * time.Minute)) {
t.Fatal()
}

if v.SampleSize() != 2 {
t.Fatal()
}

if v.NumIntervalTasks() != 3 {
t.Fatal()
}

if v.Lag() != 2*time.Second {
t.Fatal()
}
}

0 comments on commit 39c3cf5

Please sign in to comment.