5d21e85529
* The audit worker wants to get items from the queue and process them. * The audit chore wants to create new queues and swap them in when the old queue has been processed. This change adds a "Queues" struct which handles the concurrency issues around the worker fetching a queue and the chore swapping a new queue in. It simplifies the logic of the "Queue" struct to its bare bones, so that it behaves like a normal queue with no need to understand the details of swapping and worker/chore interactions. Change-Id: Ic3689ede97a528e7590e98338cedddfa51794e1b
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package audit_test
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"storj.io/common/memory"
|
|
"storj.io/common/storj"
|
|
"storj.io/common/testcontext"
|
|
"storj.io/common/testrand"
|
|
"storj.io/storj/private/testplanet"
|
|
"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]
|
|
audits := satellite.Audit
|
|
audits.Worker.Loop.Pause()
|
|
audits.Chore.Loop.Pause()
|
|
|
|
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)
|
|
}
|
|
|
|
audits.Chore.Loop.TriggerWait()
|
|
queue := audits.Queues.Fetch()
|
|
require.EqualValues(t, 2, queue.Size(), "audit queue")
|
|
|
|
uniquePaths := make(map[storj.Path]struct{})
|
|
var err error
|
|
var path storj.Path
|
|
var pathCount int
|
|
for {
|
|
path, err = queue.Next()
|
|
if err != nil {
|
|
break
|
|
}
|
|
pathCount++
|
|
_, ok := uniquePaths[path]
|
|
require.False(t, ok, "expected unique path in chore queue")
|
|
|
|
uniquePaths[path] = struct{}{}
|
|
}
|
|
require.True(t, audit.ErrEmptyQueue.Has(err))
|
|
require.Equal(t, 2, pathCount)
|
|
require.Equal(t, 0, queue.Size())
|
|
|
|
// Repopulate the queue for the worker.
|
|
audits.Chore.Loop.TriggerWait()
|
|
|
|
// Make sure the worker processes the audit queue.
|
|
audits.Worker.Loop.TriggerWait()
|
|
queue = audits.Queues.Fetch()
|
|
require.EqualValues(t, 0, queue.Size(), "audit queue")
|
|
})
|
|
}
|