Files
tasks/common/checksum/crc_test.go
Roey BermanandGitHub 243effc6e1 Forbid the use of pborman/uuid and remove uses (#8541)
## What

Used the `depguard` linter to prevent importing the package and modified
all uses of it.

Also fixed a bug in the membership code where we were not updating the
next page token:

https://github.com/temporalio/temporal/pull/8541/files#diff-985dd64ffa4c6bfe0248b982dc47439b725862baa3e1f2c559b7ff522bf21969R350


## Why?

From the package README in GitHub:

> This package now leverages the github.com/google/uuid package (which
is based off an earlier version of this package).

Also, there's no point in having two uuid implementations in the
codebase.

## Test

Added the invalid import and confirmed it works:

```
../service/frontend/admin_handler_test.go:13:2: import 'github.com/pborman/uuid' is not allowed from list 'main': Importing github.com/pborman/uuid is disallowed; use github.com/google/uuid instead (depguard)
        _ "github.com/pborman/uuid"

```
2025-11-26 01:33:02 +00:00

61 lines
1.4 KiB
Go

package checksum
import (
"sync"
"sync/atomic"
"testing"
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
commonpb "go.temporal.io/api/common/v1"
workflowpb "go.temporal.io/api/workflow/v1"
"go.temporal.io/server/common"
"google.golang.org/protobuf/types/known/timestamppb"
)
func TestCRC32OverProto(t *testing.T) {
// note: do not use a struct with map since
// iteration order is not guaranteed in Go and
// so, each call to thrift encode will result in
// different set of serialized bytes
obj := &workflowpb.WorkflowExecutionInfo{
Execution: &commonpb.WorkflowExecution{
WorkflowId: uuid.NewString(),
RunId: uuid.NewString(),
},
StartTime: timestamppb.New(time.Now().UTC()),
HistoryLength: 550,
}
parallism := 10
loopCount := 100
successCount := int64(0)
startC := make(chan struct{})
doneWG := sync.WaitGroup{}
doneWG.Add(parallism)
for i := 0; i < parallism; i++ {
go func() {
defer doneWG.Done()
<-startC
for count := 0; count < loopCount; count++ {
csum, err := GenerateCRC32(obj, 1)
if err != nil {
return
}
if err := Verify(obj, csum); err != nil {
return
}
atomic.AddInt64(&successCount, 1)
}
}()
}
close(startC)
success := common.AwaitWaitGroup(&doneWG, time.Second)
assert.True(t, success, "timed out waiting for goroutines to finish")
assert.Equal(t, int64(parallism*loopCount), successCount)
}