Since file deletions happen asynchronously, sometimes it is possible that the deleted file still lingers around. To ensure this does not cause test failures, retry a few times before just returning the contents of the directory.
(tmpDir string, secsToWait int)
| 2235 | // To ensure this does not cause test failures, retry a few times |
| 2236 | // before just returning the contents of the directory. |
| 2237 | func waitForCompactionCleanup(tmpDir string, secsToWait int) ( |
| 2238 | fileInfos []os.FileInfo, err error) { |
| 2239 | fileInfos, err = ioutil.ReadDir(tmpDir) |
| 2240 | if err != nil { |
| 2241 | return |
| 2242 | } |
| 2243 | for retry := secsToWait; retry > 0 && len(fileInfos) != 1; retry-- { |
| 2244 | file, erro := os.Open(tmpDir) |
| 2245 | if erro != nil { |
| 2246 | return fileInfos, erro |
| 2247 | } |
| 2248 | file.Sync() |
| 2249 | file.Close() |
| 2250 | |
| 2251 | time.Sleep(1 * time.Second) |
| 2252 | fileInfos, err = ioutil.ReadDir(tmpDir) |
| 2253 | } |
| 2254 | return |
| 2255 | } |
| 2256 | |
| 2257 | func TestCompactionWithAndWithoutRegularSync(t *testing.T) { |
| 2258 | numItems := 1000000 |
no test coverage detected
searching dependent graphs…