internal/testplanet: improve test speed (#2280)

This commit is contained in:
Egon Elbre 2019-06-21 19:41:39 +03:00 committed by Stefan Benten
parent 3d6b25a043
commit 69c2cbacdf

View File

@ -4,10 +4,11 @@
package testplanet_test package testplanet_test
import ( import (
"bytes"
"context" "context"
"crypto/rand" "fmt"
"math/rand"
"path/filepath" "path/filepath"
"strconv"
"testing" "testing"
"time" "time"
@ -26,21 +27,50 @@ import (
"storj.io/storj/uplink" "storj.io/storj/uplink"
) )
func TestUploadDownload(t *testing.T) { func TestUplinksParallel(t *testing.T) {
const uplinkCount = 3
const parallelCount = 2
testplanet.Run(t, testplanet.Config{ testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1, SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: uplinkCount,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
expectedData := make([]byte, 1*memory.MiB) satellite := planet.Satellites[0]
_, err := rand.Read(expectedData)
assert.NoError(t, err)
err = planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", "test/path", expectedData) var group errgroup.Group
assert.NoError(t, err) for i := range planet.Uplinks {
uplink := planet.Uplinks[i]
data, err := planet.Uplinks[0].Download(ctx, planet.Satellites[0], "testbucket", "test/path") for p := 0; p < parallelCount; p++ {
assert.NoError(t, err) suffix := fmt.Sprintf("-%d-%d", i, p)
group.Go(func() error {
random := rand.New(rand.NewSource(rand.Int63()))
assert.Equal(t, expectedData, data) data := make([]byte, 100*memory.KiB.Int()+random.Intn(500)*memory.KiB.Int())
_, err := random.Read(data)
if err != nil {
return err
}
err = uplink.Upload(ctx, satellite, "testbucket"+suffix, "test/path"+suffix, data)
if err != nil {
return err
}
downloaded, err := uplink.Download(ctx, satellite, "testbucket"+suffix, "test/path"+suffix)
if err != nil {
return err
}
if !bytes.Equal(data, downloaded) {
return fmt.Errorf("upload != download data: %s", suffix)
}
return nil
})
}
}
err := group.Wait()
require.NoError(t, err)
}) })
} }
@ -116,92 +146,6 @@ func TestDownloadWithSomeNodesOffline(t *testing.T) {
}) })
} }
func TestUploadDownloadOneUplinksInParallel(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
dataToUpload := make([][]byte, 5)
for i := 0; i < len(dataToUpload); i++ {
dataToUpload[i] = make([]byte, 100*memory.KiB.Int()+(i*100*memory.KiB.Int()))
_, err := rand.Read(dataToUpload[i])
require.NoError(t, err)
}
var group errgroup.Group
for i, data := range dataToUpload {
index := strconv.Itoa(i)
uplink := planet.Uplinks[0]
satellite := planet.Satellites[0]
data := data
group.Go(func() error {
return uplink.Upload(ctx, satellite, "testbucket"+index, "test/path"+index, data)
})
}
err := group.Wait()
require.NoError(t, err)
for i, data := range dataToUpload {
index := strconv.Itoa(i)
uplink := planet.Uplinks[0]
satellite := planet.Satellites[0]
expectedData := data
group.Go(func() error {
data, err := uplink.Download(ctx, satellite, "testbucket"+index, "test/path"+index)
require.Equal(t, expectedData, data)
return err
})
}
err = group.Wait()
require.NoError(t, err)
})
}
func TestUploadDownloadMultipleUplinksInParallel(t *testing.T) {
numberOfUplinks := 5
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: numberOfUplinks,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
dataToUpload := make([][]byte, numberOfUplinks)
for i := 0; i < len(dataToUpload); i++ {
dataToUpload[i] = make([]byte, 100*memory.KiB.Int()+(i*100*memory.KiB.Int()))
_, err := rand.Read(dataToUpload[i])
require.NoError(t, err)
}
var group errgroup.Group
for i, data := range dataToUpload {
index := strconv.Itoa(i)
uplink := planet.Uplinks[i]
satellite := planet.Satellites[0]
data := data
group.Go(func() error {
return uplink.Upload(ctx, satellite, "testbucket"+index, "test/path"+index, data)
})
}
err := group.Wait()
require.NoError(t, err)
for i, data := range dataToUpload {
index := strconv.Itoa(i)
uplink := planet.Uplinks[i]
satellite := planet.Satellites[0]
expectedData := data
group.Go(func() error {
data, err := uplink.Download(ctx, satellite, "testbucket"+index, "test/path"+index)
require.Equal(t, expectedData, data)
return err
})
}
err = group.Wait()
require.NoError(t, err)
})
}
type piecestoreMock struct { type piecestoreMock struct {
} }