HOTFIX: fix flaky StateDirectoryTest.shouldReturnEmptyArrayIfListFile…#8310
Conversation
abbccdda
left a comment
There was a problem hiding this comment.
LGTM. @ableegoldman Could you take a look?
There was a problem hiding this comment.
We don't want to remove the stateDir entirely, because then stateDir.exists will return false and we won't actually call listFiles which is what this test is trying to test. Can we just rename to "state-renamed" + TestUtils.randomString(5)? Or, clean up the previous contents at the beginning of the test?
That said, cleanUp should be called after every test, so there shouldn't be any left over state...right? cc/ @guozhangwang
There was a problem hiding this comment.
That's true, but I suspect that this leftover folder is not from this test suite but likely from others? I think the right fix here should be to check which test (highly doubt it is one of the StateDirectoryTest because of cleanup ) has this leftover and fix that one instead.
There was a problem hiding this comment.
Hm...we actually create a new stateDir with 5 random characters so that seems pretty unlikely.
@chia7712 For now we can just add a + TestUtils.randomString(5) to the renamed name to fix the flakyness. In fact we can actually remove everything before stateDir.rename in this test, it's identical to what's done in @Before. I think it's leftover from a different approach to writing this test.
There was a problem hiding this comment.
@guozhangwang @ableegoldman thanks for feedback! I understand the purpose of this test case now.
That said, cleanUp should be called after every test, so there shouldn't be any left over state...right?
That's true, but I suspect that this leftover folder is not from this test suite but likely from others?
not really. java File is an immutable object so the renameTo does not change the file point. (see https://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true).
We don't want to remove the stateDir entirely, because then stateDir.exists will return false and we won't actually call listFiles which is what this test is trying to test.
As file is immutable, stateDir.exists returns false after renaming.
It seems to me the solution is to remove all files in StateDirectory.stageDir instead of renaming. It fix following issues.
- the stage dir is not deleted by
after() - stateDir.exists return false as origin file is existent
There was a problem hiding this comment.
@chia7712 @ableegoldman I think about this case a bit more, and I think maybe we can refactor this test by creating the stateDir as a file and not a directory, so that stateDir.exists would return true while listFiles would return null. WDYT?
There was a problem hiding this comment.
ok. I was confused by the inconsistent naming. the folder in StateDirectory should be called appDir rather than stateDir
public StateDirectory(final StreamsConfig config, final Time time, final boolean hasPersistentStores) {
final String stateDirName = config.getString(StreamsConfig.STATE_DIR_CONFIG);
final File baseDir = new File(stateDirName);
...
stateDir = new File(baseDir, appId);
...
}Correct my previous comments :(
the targets I have to address are shown below.
- make sure the
stateDirin StateDirectory points to nothing in order to makelistFilesreturn null. - make sure the
stateDirin test case is deleted byafter
There was a problem hiding this comment.
I think about this case a bit more, and I think maybe we can refactor this test by creating the stateDir as a file and not a directory, so that stateDir.exists would return true while listFiles would return null. WDYT?
yep. that is what I have done :)
bad4fc4 to
81a7328
Compare
|
Thanks for the quick fix @chia7712 !! Merging to trunk now. |
|
The latest build seems still flaky but on a different test case: I'll take a look into this. |
|
I've pushed a HOTFIX commit to address this issue, cc @mjsax @ableegoldman |
|
StateDirectoryTest.shouldReturnEmptyArrayIfListFilesReturnsNullalways moves the stage dir to /tmp/state-renamed so it always fails if there is already a folder (for example, the stuff leaved by previous test)We should just delete the folder to make stage dir disappear
related to #8304
Committer Checklist (excluded from commit message)