refactor: speed up tests a bit (#28)
ci/woodpecker/push/govulncheck Pipeline was successful Details
ci/woodpecker/push/test Pipeline was successful Details

Reviewed-on: twhelp/corev3#28
This commit is contained in:
Dawid Wysokiński 2024-03-16 06:00:29 +00:00
parent 096ca396db
commit 9bfbcf4ad7
4 changed files with 484 additions and 428 deletions

View File

@ -25,6 +25,7 @@ steps:
image: *go_image
pull: true
commands:
- go mod vendor
- make generate
test:

View File

@ -12,6 +12,7 @@ import (
"os"
"os/signal"
"path"
"sync"
"syscall"
"testing"
"time"
@ -197,8 +198,15 @@ func TestDataSync(t *testing.T) {
require.NoError(t, dataSyncSvc.Sync(ctx))
var wg sync.WaitGroup
var expectedServers []map[string]any
readJSONFile(t, filesys, path.Join("expected", "servers.json"), &expectedServers)
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithTf(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -274,9 +282,15 @@ func TestDataSync(t *testing.T) {
)
}
}, 60*time.Second, time.Second, "servers")
}()
var expectedTribes []map[string]any
readJSONFile(t, filesys, path.Join("expected", "tribes.json"), &expectedTribes)
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -341,9 +355,15 @@ func TestDataSync(t *testing.T) {
}
}
}, 60*time.Second, time.Second, "tribes")
}()
var expectedPlayers []map[string]any
readJSONFile(t, filesys, path.Join("expected", "players.json"), &expectedPlayers)
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -405,9 +425,15 @@ func TestDataSync(t *testing.T) {
}
}
}, 60*time.Second, time.Second, "players")
}()
var expectedVillages []map[string]any
readJSONFile(t, filesys, path.Join("expected", "villages.json"), &expectedVillages)
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -452,9 +478,15 @@ func TestDataSync(t *testing.T) {
assert.Equal(collect, expected["ProfileURL"], actual.ProfileURL().String(), msg)
}
}, 60*time.Second, time.Second, "villages")
}()
var expectedTribeChanges []map[string]any
readJSONFile(t, filesys, path.Join("expected", "tribe-changes.json"), &expectedTribeChanges)
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithT(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -493,6 +525,9 @@ func TestDataSync(t *testing.T) {
assert.EqualValues(collect, expected["NewTribeID"], actual.NewTribeID(), msg)
}
}, 60*time.Second, time.Second, "tribe changes")
}()
wg.Wait()
})
}
}

View File

@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"slices"
"sync"
"syscall"
"testing"
"time"
@ -143,6 +144,12 @@ func TestSnapshotCreation(t *testing.T) {
require.NoError(t, snapshotSvc.Create(ctx))
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithTf(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -172,6 +179,11 @@ func TestSnapshotCreation(t *testing.T) {
require.NoError(collect, listParams.SetCursor(res.Next()))
}
}, 30*time.Second, 500*time.Millisecond, "servers")
}()
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithTf(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -258,6 +270,11 @@ func TestSnapshotCreation(t *testing.T) {
//nolint:testifylint
assert.Equal(collect, len(allTribes), cnt)
}, 30*time.Second, 500*time.Millisecond, "tribes")
}()
wg.Add(1)
go func() {
defer wg.Done()
assert.EventuallyWithTf(t, func(collect *assert.CollectT) {
require.NoError(collect, ctx.Err())
@ -342,4 +359,7 @@ func TestSnapshotCreation(t *testing.T) {
//nolint:testifylint
assert.Equal(collect, len(allPlayers), cnt)
}, 30*time.Second, 500*time.Millisecond, "players")
}()
wg.Wait()
}

View File

@ -159,7 +159,7 @@ func (rmq *RabbitMQ) Close() error {
return nil
}
type TopicNameGenerator func(topic string) string
type TopicNameGenerator amqp.QueueNameGenerator
func NewPubSub(
tb watermilltest.TestingTB,