Skip to content

Commit

Permalink
Each test needs it's own variable to track the current time (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-milkey committed Sep 17, 2020
1 parent cd3e7a5 commit 23019e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions test/gnmi/subscribestatediagstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
)

var (
previousTime = time.Now().Add(-5 * time.Minute)
previousTimeDiags time.Time
)

func filterResponse(response *diags.OpStateResponse) bool {
Expand All @@ -41,6 +41,8 @@ func filterResponse(response *diags.OpStateResponse) bool {

// TestSubscribeStateDiags tests a stream subscription to updates to a device using the diags API
func (s *TestSuite) TestSubscribeStateDiags(t *testing.T) {
previousTimeDiags = time.Now().Add(-5 * time.Minute)

// Bring up a new simulated device
simulator := gnmi.CreateSimulator(t)
deviceName := simulator.Name()
Expand Down Expand Up @@ -82,6 +84,6 @@ func validateDiagsStateResponse(t *testing.T, resp *diags.OpStateResponse) {
updatedTimeString := resp.Pathvalue.Value.ValueToString()
updatedTime, timeParseError := time.Parse("2006-01-02T15:04:05Z-07:00", updatedTimeString)
assert.NoError(t, timeParseError, "Error parsing time string from path value")
assert.True(t, previousTime.Before(updatedTime), "Path time value is not in the future %v", resp)
previousTime = updatedTime
assert.True(t, previousTimeDiags.Before(updatedTime), "Path time value is not in the future %v", resp)
previousTimeDiags = updatedTime
}
10 changes: 7 additions & 3 deletions test/gnmi/subscribestategnmitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ import (
"github.com/stretchr/testify/assert"
)

var (
previousTimeState time.Time
)

// TestSubscribeStateGnmi tests a stream subscription to updates to a device
func (s *TestSuite) TestSubscribeStateGnmi(t *testing.T) {
const dateTimePath = "/system/state/current-datetime"

previousTime = time.Now().Add(-5 * time.Minute)
previousTimeState = time.Now().Add(-5 * time.Minute)

// Bring up a new simulated device
simulator := gnmi.CreateSimulator(t)
Expand Down Expand Up @@ -137,8 +141,8 @@ func validateGnmiStateUpdateResponse(t *testing.T, update *gpb.SubscribeResponse
updatedTime, timeParseError := time.Parse("2006-01-02T15:04:05Z-07:00", updatedTimeString)
assert.NoError(t, timeParseError)

assert.True(t, previousTime.Before(updatedTime), "Path time value is not in the future %v", update)
previousTime = updatedTime
assert.True(t, previousTimeState.Before(updatedTime), "Path time value is not in the future %v", update)
previousTimeState = updatedTime
}

func validateGnmiStateSyncResponse(t *testing.T, sync *gpb.SubscribeResponse_SyncResponse) {
Expand Down

0 comments on commit 23019e4

Please sign in to comment.