Skip to content

Commit

Permalink
Simplify large snapshot test (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar authored Jul 2, 2023
1 parent 9ba4676 commit 583d351
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Binary file added fixtures/3million.bin.s2
Binary file not shown.
28 changes: 8 additions & 20 deletions snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
"io"
"math"
"math/rand"
"os"
"runtime"
"sync"
"sync/atomic"
"testing"

"github.com/kelindar/async"
"github.com/kelindar/column/commit"
"github.com/klauspost/compress/s2"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -203,30 +205,16 @@ func TestSnapshot(t *testing.T) {
}

func TestLargeSnapshot(t *testing.T) {
amount := 3_000_000
buffer := bytes.NewBuffer(nil)
input := loadPlayers(amount)
const amount = 3_000_000

var wg sync.WaitGroup
wg.Add(amount)
go func() {
for i := 0; i < amount; i++ {
assert.NoError(t, input.QueryAt(uint32(i), func(r Row) error {
r.SetString("name", "Roman")
return nil
}))
wg.Done()
}
}()

// Start snapshotting
assert.NoError(t, input.Snapshot(buffer))
assert.NotZero(t, buffer.Len())
encoded, err := os.ReadFile("fixtures/3million.bin.s2")
assert.NoError(t, err)
input, err := s2.Decode(nil, encoded)
assert.NoError(t, err)

// Restore the snapshot
wg.Wait()
output := newEmpty(amount)
assert.NoError(t, output.Restore(buffer))
assert.NoError(t, output.Restore(bytes.NewBuffer(input)))
assert.Equal(t, amount, output.Count())
}

Expand Down

0 comments on commit 583d351

Please sign in to comment.