@@ -106,17 +106,29 @@ func (t *testSyncerSuite) TestACKSentAfterFsync() {
106
106
// Define binlogDir and timeout
107
107
binlogDir := "./var"
108
108
os .RemoveAll (binlogDir )
109
+ err := os .MkdirAll (binlogDir , 0755 )
110
+ require .NoError (t .T (), err )
109
111
timeout := 5 * time .Second
110
112
111
113
// Create channels for signaling
112
114
fsyncedChan := make (chan struct {}, 1 )
113
115
ackedChan := make (chan struct {}, 1 )
114
116
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
+
115
129
// Set up the BackupEventHandler with fsyncedChan
116
130
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 ,
120
132
fsyncedChan : fsyncedChan ,
121
133
}
122
134
@@ -131,7 +143,7 @@ func (t *testSyncerSuite) TestACKSentAfterFsync() {
131
143
pos := mysql.Position {Name : "" , Pos : uint32 (0 )}
132
144
go func () {
133
145
// Start backup (this will block until timeout)
134
- err := t .b .StartBackupWithHandler (pos , timeout , backupHandler . handler )
146
+ err := t .b .StartBackupWithHandler (pos , timeout , handler )
135
147
require .NoError (t .T (), err )
136
148
}()
137
149
0 commit comments