forked from go-mysql-org/go-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_test.go
48 lines (37 loc) · 961 Bytes
/
backup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package replication
import (
"context"
"os"
"time"
"github.com/stretchr/testify/require"
"github.com/go-mysql-org/go-mysql/mysql"
)
func (t *testSyncerSuite) TestStartBackupEndInGivenTime() {
t.setupTest(mysql.MySQLFlavor)
resetBinaryLogs := "RESET BINARY LOGS AND GTIDS"
if eq, err := t.c.CompareServerVersion("8.4.0"); (err == nil) && (eq < 0) {
resetBinaryLogs = "RESET MASTER"
}
t.testExecute(resetBinaryLogs)
for times := 1; times <= 2; times++ {
t.testSync(nil)
t.testExecute("FLUSH LOGS")
}
binlogDir := "./var"
os.RemoveAll(binlogDir)
timeout := 2 * time.Second
done := make(chan bool)
go func() {
err := t.b.StartBackup(binlogDir, mysql.Position{Name: "", Pos: uint32(0)}, timeout)
require.NoError(t.T(), err)
done <- true
}()
failTimeout := 5 * timeout
ctx, _ := context.WithTimeout(context.Background(), failTimeout)
select {
case <-done:
return
case <-ctx.Done():
t.T().Fatal("time out error")
}
}