Skip to content

Commit 4fa8f67

Browse files
author
Dylan Terry
committed
Fix TestACKSentAfterFsync by creating 'var' directory and adjusting the event handler construction
1 parent 1b08ee2 commit 4fa8f67

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

replication/backup_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,29 @@ func (t *testSyncerSuite) TestACKSentAfterFsync() {
106106
// Define binlogDir and timeout
107107
binlogDir := "./var"
108108
os.RemoveAll(binlogDir)
109+
err := os.MkdirAll(binlogDir, 0755)
110+
require.NoError(t.T(), err)
109111
timeout := 5 * time.Second
110112

111113
// Create channels for signaling
112114
fsyncedChan := make(chan struct{}, 1)
113115
ackedChan := make(chan struct{}, 1)
114116

117+
// Custom handler returning TestWriteCloser
118+
handler := func(binlogFilename string) (io.WriteCloser, error) {
119+
file, err := os.OpenFile(path.Join(binlogDir, binlogFilename), os.O_CREATE|os.O_WRONLY, 0644)
120+
if err != nil {
121+
return nil, err
122+
}
123+
return &TestWriteCloser{
124+
file: file,
125+
syncCalled: fsyncedChan,
126+
}, nil
127+
}
128+
115129
// Set up the BackupEventHandler with fsyncedChan
116130
backupHandler := &BackupEventHandler{
117-
handler: func(binlogFilename string) (io.WriteCloser, error) {
118-
return os.OpenFile(path.Join(binlogDir, binlogFilename), os.O_CREATE|os.O_WRONLY, 0644)
119-
},
131+
handler: handler,
120132
fsyncedChan: fsyncedChan,
121133
}
122134

@@ -131,7 +143,7 @@ func (t *testSyncerSuite) TestACKSentAfterFsync() {
131143
pos := mysql.Position{Name: "", Pos: uint32(0)}
132144
go func() {
133145
// Start backup (this will block until timeout)
134-
err := t.b.StartBackupWithHandler(pos, timeout, backupHandler.handler)
146+
err := t.b.StartBackupWithHandler(pos, timeout, handler)
135147
require.NoError(t.T(), err)
136148
}()
137149

0 commit comments

Comments
 (0)