Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidporter-id-au committed May 10, 2024
1 parent 554cddf commit 9bfb16a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 3 additions & 5 deletions common/testing/testdatagen/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ import (

// NewFuzzer creates a new fuzzer, notes down the deterministic seed
func New(t *testing.T, generatorFuncs ...interface{}) *fuzz.Fuzzer {
return NewWithNilChance(t, 0.2, generatorFuncs...)
return NewWithNilChance(t, time.Now().UnixNano(), 0.2, generatorFuncs...)
}

// NewFuzzer creates a new fuzzer, notes down the deterministic seed
func NewWithNilChance(t *testing.T, nilchance float32, generatorFuncs ...interface{}) *fuzz.Fuzzer {
seed := time.Now().Unix()
func NewWithNilChance(t *testing.T, seed int64, nilchance float32, generatorFuncs ...interface{}) *fuzz.Fuzzer {
t.Log("Fuzz Seed:", seed)

return fuzz.NewWithSeed(time.Now().Unix()).Funcs(generatorFuncs...).NilChance(float64(nilchance))
return fuzz.NewWithSeed(seed).Funcs(generatorFuncs...).NilChance(float64(nilchance))
}
22 changes: 21 additions & 1 deletion service/history/execution/mutable_state_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"testing"
"time"

"math/rand"
"github.com/golang/mock/gomock"
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1900,11 +1901,16 @@ func TestMutableStateBuilder_CopyToPersistence_roundtrip(t *testing.T) {
for i := 0; i <= 100; i++ {
ctrl := gomock.NewController(t)

fuzzer := testdatagen.NewWithNilChance(t, 0)
seed := int64(rand.Int())
fuzzer := testdatagen.NewWithNilChance(t, seed, 0)

execution := &persistence.WorkflowMutableState{}
fuzzer.Fuzz(&execution)

// checksum is a calculated value, zero it out because
// it'll be overwridden during the constructor setup
execution.Checksum = checksum.Checksum{}

shardContext := shard.NewMockContext(ctrl)
mockCache := events.NewMockCache(ctrl)
mockDomainCache := cache.NewMockDomainCache(ctrl)
Expand All @@ -1930,6 +1936,20 @@ func TestMutableStateBuilder_CopyToPersistence_roundtrip(t *testing.T) {

out := msb.CopyToPersistence()


assert.Equal(t, execution.ActivityInfos, out.ActivityInfos, "activityinfos mismatch")
assert.Equal(t, execution.TimerInfos, out.TimerInfos, "timerinfos mismatch")
assert.Equal(t, execution.ChildExecutionInfos, out.ChildExecutionInfos, "child executino info mismatches")
assert.Equal(t, execution.RequestCancelInfos, out.RequestCancelInfos, "request cancellantion info mismatches")
assert.Equal(t, execution.SignalInfos, out.SignalInfos, "signal info mismatches")
assert.Equal(t, execution.SignalRequestedIDs, out.SignalRequestedIDs, "signal request ids mismaches")
assert.Equal(t, execution.ExecutionInfo, out.ExecutionInfo, "execution info mismatches")
assert.Equal(t, execution.BufferedEvents, out.BufferedEvents, "buffered events mismatch")
assert.Equal(t, execution.VersionHistories, out.VersionHistories, "version histories")
assert.Equal(t, execution.Checksum, out.Checksum, "checksum mismatch")
assert.Equal(t, execution.ReplicationState, out.ReplicationState, "replication state mismatch")
assert.Equal(t, execution.ExecutionStats, out.ExecutionStats, "execution stats mismatch")

assert.Equal(t, execution, out)

}
Expand Down

0 comments on commit 9bfb16a

Please sign in to comment.