satellite/repair: avoid TestDBAccess
Change-Id: I34adb58cd67fba5917032f2f328d75b1c4afdbbf
This commit is contained in:
parent
0771cdb0b1
commit
28ea63be92
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"storj.io/storj/satellite/internalpb"
|
||||
"storj.io/storj/satellite/satellitedb/dbx"
|
||||
)
|
||||
|
||||
// RepairQueue implements queueing for segments that need repairing.
|
||||
@ -29,7 +28,6 @@ type RepairQueue interface {
|
||||
// Count counts the number of segments in the repair queue.
|
||||
Count(ctx context.Context) (count int, err error)
|
||||
|
||||
// TestDBAccess returns raw RepairQueue database access for test purposes.
|
||||
// TODO: remove dependency.
|
||||
TestDBAccess() *dbx.DB
|
||||
// TestingSetAttemptedTime sets attempted time for a repairpath.
|
||||
TestingSetAttemptedTime(ctx context.Context, repairpath []byte, t time.Time) (rowsAffected int64, err error)
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
package queue_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
@ -16,7 +15,6 @@ import (
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/satellite/internalpb"
|
||||
"storj.io/storj/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
@ -68,32 +66,19 @@ func TestOrder(t *testing.T) {
|
||||
require.False(t, alreadyInserted)
|
||||
}
|
||||
|
||||
// TODO: remove dependency on *dbx.DB
|
||||
dbAccess := db.RepairQueue().TestDBAccess()
|
||||
|
||||
err := dbAccess.WithTx(ctx, func(ctx context.Context, tx *dbx.Tx) error {
|
||||
updateList := []struct {
|
||||
path []byte
|
||||
attempted time.Time
|
||||
}{
|
||||
{recentRepairPath, time.Now()},
|
||||
{oldRepairPath, time.Now().Add(-7 * time.Hour)},
|
||||
{olderRepairPath, time.Now().Add(-8 * time.Hour)},
|
||||
}
|
||||
for _, item := range updateList {
|
||||
res, err := tx.Tx.ExecContext(ctx, dbAccess.Rebind(`UPDATE injuredsegments SET attempted = ? WHERE path = ?`), item.attempted, item.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
count, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
require.EqualValues(t, 1, count)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
updateList := []struct {
|
||||
path []byte
|
||||
attempted time.Time
|
||||
}{
|
||||
{recentRepairPath, time.Now()},
|
||||
{oldRepairPath, time.Now().Add(-7 * time.Hour)},
|
||||
{olderRepairPath, time.Now().Add(-8 * time.Hour)},
|
||||
}
|
||||
for _, item := range updateList {
|
||||
rowsAffected, err := db.RepairQueue().TestingSetAttemptedTime(ctx, item.path, item.attempted)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 1, rowsAffected)
|
||||
}
|
||||
|
||||
// path with attempted = null should be selected first
|
||||
injuredSeg, err := repairQueue.Select(ctx)
|
||||
@ -132,9 +117,6 @@ func TestOrderHealthyPieces(t *testing.T) {
|
||||
// ("path/g", 10, null)
|
||||
// ("path/h", 10, now-8h)
|
||||
|
||||
// TODO: remove dependency on *dbx.DB
|
||||
dbAccess := db.RepairQueue().TestDBAccess()
|
||||
|
||||
// insert the 8 segments according to the plan above
|
||||
injuredSegList := []struct {
|
||||
path []byte
|
||||
@ -164,11 +146,9 @@ func TestOrderHealthyPieces(t *testing.T) {
|
||||
|
||||
// next, if applicable, update the "attempted at" timestamp
|
||||
if !item.attempted.IsZero() {
|
||||
res, err := dbAccess.ExecContext(ctx, dbAccess.Rebind(`UPDATE injuredsegments SET attempted = ? WHERE path = ?`), item.attempted, item.path)
|
||||
rowsAffected, err := db.RepairQueue().TestingSetAttemptedTime(ctx, item.path, item.attempted)
|
||||
require.NoError(t, err)
|
||||
count, err := res.RowsAffected()
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 1, count)
|
||||
require.EqualValues(t, 1, rowsAffected)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,6 @@ type repairQueue struct {
|
||||
db *satelliteDB
|
||||
}
|
||||
|
||||
func (r *repairQueue) TestDBAccess() *dbx.DB {
|
||||
return r.db.DB
|
||||
}
|
||||
|
||||
func (r *repairQueue) Insert(ctx context.Context, seg *internalpb.InjuredSegment, segmentHealth float64) (alreadyInserted bool, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
// insert if not exists, or update healthy count if does exist
|
||||
@ -151,3 +147,14 @@ func (r *repairQueue) Count(ctx context.Context) (count int, err error) {
|
||||
|
||||
return count, Error.Wrap(err)
|
||||
}
|
||||
|
||||
// TestingSetAttemptedTime sets attempted time for a repairpath.
|
||||
func (r *repairQueue) TestingSetAttemptedTime(ctx context.Context, repairpath []byte, t time.Time) (rowsAffected int64, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
res, err := r.db.ExecContext(ctx, r.db.Rebind(`UPDATE injuredsegments SET attempted = ? WHERE path = ?`), t, repairpath)
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
count, err := res.RowsAffected()
|
||||
return count, Error.Wrap(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user