Skip to content

Commit de74234

Browse files
author
Niall Pemberton
committed
Get a new File instance every time a file is "touched" - hopefully might reduce test failures on Gump/Continuum (that I can't reproduce locally)
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@922465 13f79535-47bb-0310-9956-ffa450edef68
1 parent d52d144 commit de74234

1 file changed

Lines changed: 28 additions & 26 deletions

File tree

src/test/org/apache/commons/io/monitor/FilesystemObserverTestCase.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void testDirectory() {
127127
checkAndNotify();
128128
checkCollectionsEmpty("C");
129129

130-
touch(testDirAFile4);
130+
testDirAFile4 = touch(testDirAFile4);
131131
FileUtils.deleteDirectory(testDirB);
132132
checkAndNotify();
133133
checkCollectionSizes("D", 0, 0, 1, 0, 1, 1);
@@ -165,8 +165,8 @@ public void testFileCreate() {
165165
checkCollectionsEmpty("A");
166166
File testDirA = new File(testDir, "test-dir-A");
167167
testDirA.mkdir();
168-
touch(testDir);
169-
touch(testDirA);
168+
testDir = touch(testDir);
169+
testDirA = touch(testDirA);
170170
File testDirAFile1 = new File(testDirA, "A-file1.java");
171171
File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
172172
File testDirAFile3 = new File(testDirA, "A-file3.java");
@@ -191,24 +191,24 @@ public void testFileCreate() {
191191
checkCollectionsEmpty("C");
192192

193193
// Create file with name < first entry
194-
touch(testDirAFile1);
195-
touch(testDirA);
194+
testDirAFile1 = touch(testDirAFile1);
195+
testDirA = touch(testDirA);
196196
checkAndNotify();
197197
checkCollectionSizes("D", 0, 1, 0, 1, 0, 0);
198198
assertTrue("D testDirAFile1 exists", testDirAFile1.exists());
199199
assertTrue("D testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
200200

201201
// Create file with name between 2 entries
202-
touch(testDirAFile3);
203-
touch(testDirA);
202+
testDirAFile3 = touch(testDirAFile3);
203+
testDirA = touch(testDirA);
204204
checkAndNotify();
205205
checkCollectionSizes("E", 0, 1, 0, 1, 0, 0);
206206
assertTrue("E testDirAFile3 exists", testDirAFile3.exists());
207207
assertTrue("E testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
208208

209209
// Create file with name > last entry
210-
touch(testDirAFile5);
211-
touch(testDirA);
210+
testDirAFile5 = touch(testDirAFile5);
211+
testDirA = touch(testDirA);
212212
checkAndNotify();
213213
checkCollectionSizes("F", 0, 1, 0, 1, 0, 0);
214214
assertTrue("F testDirAFile5 exists", testDirAFile5.exists());
@@ -227,8 +227,8 @@ public void testFileUpdate() {
227227
checkCollectionsEmpty("A");
228228
File testDirA = new File(testDir, "test-dir-A");
229229
testDirA.mkdir();
230-
touch(testDir);
231-
touch(testDirA);
230+
testDir = touch(testDir);
231+
testDirA = touch(testDirA);
232232
File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
233233
File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
234234
File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
@@ -253,22 +253,22 @@ public void testFileUpdate() {
253253
checkCollectionsEmpty("C");
254254

255255
// Update first entry
256-
touch(testDirAFile1);
257-
touch(testDirA);
256+
testDirAFile1 = touch(testDirAFile1);
257+
testDirA = touch(testDirA);
258258
checkAndNotify();
259259
checkCollectionSizes("D", 0, 1, 0, 0, 1, 0);
260260
assertTrue("D testDirAFile1", listener.getChangedFiles().contains(testDirAFile1));
261261

262262
// Update file with name between 2 entries
263-
touch(testDirAFile3);
264-
touch(testDirA);
263+
testDirAFile3 = touch(testDirAFile3);
264+
testDirA = touch(testDirA);
265265
checkAndNotify();
266266
checkCollectionSizes("E", 0, 1, 0, 0, 1, 0);
267267
assertTrue("E testDirAFile3", listener.getChangedFiles().contains(testDirAFile3));
268268

269269
// Update last entry
270-
touch(testDirAFile5);
271-
touch(testDirA);
270+
testDirAFile5 = touch(testDirAFile5);
271+
testDirA = touch(testDirA);
272272
checkAndNotify();
273273
checkCollectionSizes("F", 0, 1, 0, 0, 1, 0);
274274
assertTrue("F testDirAFile5", listener.getChangedFiles().contains(testDirAFile5));
@@ -286,8 +286,8 @@ public void testFileDelete() {
286286
checkCollectionsEmpty("A");
287287
File testDirA = new File(testDir, "test-dir-A");
288288
testDirA.mkdir();
289-
touch(testDir);
290-
touch(testDirA);
289+
testDir = touch(testDir);
290+
testDirA = touch(testDirA);
291291
File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
292292
File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
293293
File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
@@ -313,23 +313,23 @@ public void testFileDelete() {
313313

314314
// Delete first entry
315315
FileUtils.deleteQuietly(testDirAFile1);
316-
touch(testDirA);
316+
testDirA = touch(testDirA);
317317
checkAndNotify();
318318
checkCollectionSizes("D", 0, 1, 0, 0, 0, 1);
319319
assertFalse("D testDirAFile1 exists", testDirAFile1.exists());
320320
assertTrue("D testDirAFile1", listener.getDeletedFiles().contains(testDirAFile1));
321321

322322
// Delete file with name between 2 entries
323323
FileUtils.deleteQuietly(testDirAFile3);
324-
touch(testDirA);
324+
testDirA = touch(testDirA);
325325
checkAndNotify();
326326
checkCollectionSizes("E", 0, 1, 0, 0, 0, 1);
327327
assertFalse("E testDirAFile3 exists", testDirAFile3.exists());
328328
assertTrue("E testDirAFile3", listener.getDeletedFiles().contains(testDirAFile3));
329329

330330
// Delete last entry
331331
FileUtils.deleteQuietly(testDirAFile5);
332-
touch(testDirA);
332+
testDirA = touch(testDirA);
333333
checkAndNotify();
334334
checkCollectionSizes("F", 0, 1, 0, 0, 0, 1);
335335
assertFalse("F testDirAFile5 exists", testDirAFile5.exists());
@@ -356,7 +356,7 @@ public void testObserveSingleFile() {
356356
assertFalse("A testDirAFile1 exists", testDirAFile1.exists());
357357

358358
// Create
359-
touch(testDirAFile1);
359+
testDirAFile1 = touch(testDirAFile1);
360360
File testDirAFile2 = touch(new File(testDirA, "A-file2.txt")); /* filter should ignore */
361361
File testDirAFile3 = touch(new File(testDirA, "A-file3.java")); /* filter should ignore */
362362
assertTrue("B testDirAFile1 exists", testDirAFile1.exists());
@@ -369,9 +369,9 @@ public void testObserveSingleFile() {
369369
assertFalse("C created", listener.getCreatedFiles().contains(testDirAFile3));
370370

371371
// Modify
372-
touch(testDirAFile1);
373-
touch(testDirAFile2);
374-
touch(testDirAFile3);
372+
testDirAFile1 = touch(testDirAFile1);
373+
testDirAFile2 = touch(testDirAFile2);
374+
testDirAFile3 = touch(testDirAFile3);
375375
checkAndNotify();
376376
checkCollectionSizes("D", 0, 0, 0, 0, 1, 0);
377377
assertTrue("D changed", listener.getChangedFiles().contains(testDirAFile1));
@@ -441,13 +441,15 @@ private File touch(File file) {
441441
long lastModified = file.exists() ? file.lastModified() : 0;
442442
try {
443443
FileUtils.touch(file);
444+
file = new File(file.getParent(), file.getName());
444445
while (lastModified == file.lastModified()) {
445446
try {
446447
Thread.sleep(50);
447448
} catch(InterruptedException ie) {
448449
// ignore
449450
}
450451
FileUtils.touch(file);
452+
file = new File(file.getParent(), file.getName());
451453
}
452454
} catch (Exception e) {
453455
fail("Touching " + file +": " + e);

0 commit comments

Comments
 (0)