2019-09-05 16:40:52 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package audit_test
|
|
|
|
|
|
|
|
import (
|
2022-11-11 23:11:40 +00:00
|
|
|
"context"
|
2019-09-05 16:40:52 +01:00
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-09-05 16:40:52 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChoreAndWorkerIntegration(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 5, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
2019-09-11 23:37:01 +01:00
|
|
|
audits := satellite.Audit
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
audits.Chore.Loop.Pause()
|
2019-09-05 16:40:52 +01:00
|
|
|
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
|
|
|
|
// Upload 2 remote files with 1 segment.
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
|
|
path := "/some/remote/path/" + strconv.Itoa(i)
|
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", path, testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
audits.Chore.Loop.TriggerWait()
|
2022-11-11 23:11:40 +00:00
|
|
|
queue := audits.VerifyQueue
|
2019-09-05 16:40:52 +01:00
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
uniqueSegments := make(map[audit.Segment]struct{})
|
2019-09-05 16:40:52 +01:00
|
|
|
var err error
|
2020-12-14 12:54:22 +00:00
|
|
|
var segment audit.Segment
|
|
|
|
var segmentCount int
|
2019-09-05 16:40:52 +01:00
|
|
|
for {
|
2022-11-11 23:11:40 +00:00
|
|
|
segment, err = queue.Next(ctx)
|
2019-09-05 16:40:52 +01:00
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2020-12-14 12:54:22 +00:00
|
|
|
segmentCount++
|
|
|
|
_, ok := uniqueSegments[segment]
|
|
|
|
require.False(t, ok, "expected unique segment in chore queue")
|
2019-09-05 16:40:52 +01:00
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
uniqueSegments[segment] = struct{}{}
|
2019-09-05 16:40:52 +01:00
|
|
|
}
|
2022-11-11 23:11:40 +00:00
|
|
|
require.True(t, audit.ErrEmptyQueue.Has(err), "expected empty queue error, but got error %+v", err)
|
2020-12-14 12:54:22 +00:00
|
|
|
require.Equal(t, 2, segmentCount)
|
2022-11-11 23:11:40 +00:00
|
|
|
requireAuditQueueEmpty(ctx, t, audits.VerifyQueue)
|
2019-09-05 16:40:52 +01:00
|
|
|
|
|
|
|
// Repopulate the queue for the worker.
|
2019-09-11 23:37:01 +01:00
|
|
|
audits.Chore.Loop.TriggerWait()
|
2019-09-05 16:40:52 +01:00
|
|
|
|
2020-08-20 14:29:02 +01:00
|
|
|
// Make sure the worker processes the audit queue.
|
2019-09-11 23:37:01 +01:00
|
|
|
audits.Worker.Loop.TriggerWait()
|
2022-11-11 23:11:40 +00:00
|
|
|
requireAuditQueueEmpty(ctx, t, audits.VerifyQueue)
|
2019-09-05 16:40:52 +01:00
|
|
|
})
|
|
|
|
}
|
2022-11-11 23:11:40 +00:00
|
|
|
|
|
|
|
func requireAuditQueueEmpty(ctx context.Context, t *testing.T, verifyQueue audit.VerifyQueue) {
|
|
|
|
entry, err := verifyQueue.Next(ctx)
|
|
|
|
require.NotNilf(t, err, "expected empty audit queue, but got entry %+v", entry)
|
|
|
|
require.Truef(t, audit.ErrEmptyQueue.Has(err), "expected empty audit queue error, but unexpectedly got error %v", err)
|
|
|
|
require.Empty(t, entry)
|
|
|
|
}
|