Files
seaweedfs/weed/server/volume_grpc_copy_count_test.go
T
ssshr-66 966692fa23 [Volume] Validate record counts after volume copy (#11238)
* validate Volume Copy record counts

* Delete s3api_object_versioning_bench_test.go

* reply ai comments
2026-09-09 02:18:18 -07:00

149 lines
3.4 KiB
Go

package weed_server
import (
"strings"
"testing"
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
)
func TestCheckCopyCounts(t *testing.T) {
tests := []struct {
name string
sourceFileCount uint64
sourceDeleteCount uint64
targetFileCount uint64
targetDeleteCount uint64
wantErr string
}{
{
name: "empty volume counts match",
},
{
name: "file and deleted counts match",
sourceFileCount: 10,
sourceDeleteCount: 3,
targetFileCount: 10,
targetDeleteCount: 3,
},
{
name: "file count differs",
sourceFileCount: 10,
sourceDeleteCount: 3,
targetFileCount: 9,
targetDeleteCount: 3,
wantErr: "file count",
},
{
name: "deleted count differs",
sourceFileCount: 10,
sourceDeleteCount: 3,
targetFileCount: 10,
targetDeleteCount: 2,
wantErr: "deleted count",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := checkCopyCounts(
&volume_server_pb.VolumeStatusResponse{
FileCount: tt.sourceFileCount,
FileDeletedCount: tt.sourceDeleteCount,
},
tt.targetFileCount,
tt.targetDeleteCount,
)
if tt.wantErr == "" {
if err != nil {
t.Fatalf("checkCopyCounts() error = %v", err)
}
return
}
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
t.Fatalf("checkCopyCounts() error = %v, want substring %q", err, tt.wantErr)
}
})
}
}
func TestCopyCountsStable(t *testing.T) {
tests := []struct {
name string
before *volume_server_pb.VolumeStatusResponse
after *volume_server_pb.VolumeStatusResponse
want bool
}{
{
name: "empty volume is stable",
before: &volume_server_pb.VolumeStatusResponse{},
after: &volume_server_pb.VolumeStatusResponse{},
want: true,
},
{
name: "matching file and deleted counts are stable",
before: &volume_server_pb.VolumeStatusResponse{
FileCount: 10,
FileDeletedCount: 3,
},
after: &volume_server_pb.VolumeStatusResponse{
FileCount: 10,
FileDeletedCount: 3,
},
want: true,
},
{
name: "read-only state changes without count changes are stable",
before: &volume_server_pb.VolumeStatusResponse{
FileCount: 10,
FileDeletedCount: 3,
IsReadOnly: true,
},
after: &volume_server_pb.VolumeStatusResponse{
FileCount: 10,
FileDeletedCount: 3,
IsReadOnly: false,
},
want: true,
},
{
name: "changed file count is not stable",
before: &volume_server_pb.VolumeStatusResponse{
FileCount: 10,
FileDeletedCount: 3,
},
after: &volume_server_pb.VolumeStatusResponse{
FileCount: 9,
FileDeletedCount: 3,
},
},
{
name: "changed deleted count is not stable",
before: &volume_server_pb.VolumeStatusResponse{
FileCount: 10,
FileDeletedCount: 3,
},
after: &volume_server_pb.VolumeStatusResponse{
FileCount: 10,
FileDeletedCount: 2,
},
},
{
name: "missing before status is not stable",
after: &volume_server_pb.VolumeStatusResponse{},
},
{
name: "missing after status is not stable",
before: &volume_server_pb.VolumeStatusResponse{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := copyCountsStable(tt.before, tt.after); got != tt.want {
t.Fatalf("copyCountsStable() = %v, want %v", got, tt.want)
}
})
}
}