Better AOFMIGRATE tests

This commit is contained in:
tidwall 2022-09-27 10:06:47 -07:00
parent cfc9673957
commit 06ebeecf4a
3 changed files with 58 additions and 13 deletions

BIN
tests/aof_legacy Normal file

Binary file not shown.

View File

@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"io"
"math/rand"
"net"
"net/http"
@ -13,6 +14,8 @@ import (
"time"
"github.com/gomodule/redigo/redis"
_ "embed"
)
func subTestAOF(g *testGroup) {
@ -288,20 +291,57 @@ func aof_READONLY_test(mc *mockServer) error {
)
}
//go:embed aof_legacy
var aofLegacy []byte
func aof_migrate_test(mc *mockServer) error {
// var aof string
// aof += "set 1 2 point 10 10\r\n"
// aof += "set 2 3 point 30 30\r\n"
// mc2, err := mockOpenServer(MockServerOptions{
// AOFFileName: "aof",
// AOFData: []byte(aof),
// Silent: true,
// Metrics: true,
// })
// if err != nil {
// return err
// }
// defer mc2.Close()
var aof []byte
for i := 0; i < 10000; i++ {
aof = append(aof, aofLegacy...)
}
var mc2 *mockServer
var err error
defer func() {
mc2.Close()
}()
mc2, err = mockOpenServer(MockServerOptions{
AOFFileName: "aof",
AOFData: aof,
Silent: true,
Metrics: true,
})
if err != nil {
return err
}
err = mc2.DoBatch(
Do("GET", "1", "2").Str(`{"type":"Point","coordinates":[20,10]}`),
)
if err != nil {
return err
}
mc2.Close()
mc2, err = mockOpenServer(MockServerOptions{
AOFFileName: "aof",
AOFData: aofLegacy[:len(aofLegacy)-1],
Silent: true,
Metrics: true,
})
if err != io.ErrUnexpectedEOF {
return fmt.Errorf("expected '%v', got '%v'", io.ErrUnexpectedEOF, err)
}
mc2.Close()
mc2, err = mockOpenServer(MockServerOptions{
AOFFileName: "aof",
AOFData: aofLegacy[1:],
Silent: true,
Metrics: true,
})
if err != io.ErrUnexpectedEOF {
return fmt.Errorf("expected '%v', got '%v'", io.ErrUnexpectedEOF, err)
}
mc2.Close()
return nil
}

View File

@ -36,6 +36,7 @@ func mockCleanup(silent bool) {
}
type mockServer struct {
closed bool
port int
mport int
conn redis.Conn
@ -169,6 +170,10 @@ func (s *mockServer) waitForStartup(ferr *error, ferrt *int32) error {
}
func (mc *mockServer) Close() {
if mc == nil || mc.closed {
return
}
mc.closed = true
mc.shutdown <- true
if mc.conn != nil {
mc.conn.Close()