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" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io"
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"
@ -13,6 +14,8 @@ import (
"time" "time"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
_ "embed"
) )
func subTestAOF(g *testGroup) { 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 { func aof_migrate_test(mc *mockServer) error {
// var aof string var aof []byte
// aof += "set 1 2 point 10 10\r\n" for i := 0; i < 10000; i++ {
// aof += "set 2 3 point 30 30\r\n" aof = append(aof, aofLegacy...)
// mc2, err := mockOpenServer(MockServerOptions{ }
// AOFFileName: "aof", var mc2 *mockServer
// AOFData: []byte(aof), var err error
// Silent: true, defer func() {
// Metrics: true, mc2.Close()
// }) }()
// if err != nil { mc2, err = mockOpenServer(MockServerOptions{
// return err AOFFileName: "aof",
// } AOFData: aof,
// defer mc2.Close() 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 return nil
} }

View File

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