Skip to content

Storage: Add TestUtil.await #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 4, 2019
Merged

Storage: Add TestUtil.await #487

merged 5 commits into from
Jun 4, 2019

Conversation

schmidt-sebastian
Copy link
Contributor

Addresses some leftover feedback from #458 and adds a shared TestUtil.await() that mimics Task.await() and removes a lot of duplicated code in our unit tests.

return;
}
Thread.sleep(1);
TestUtil.await(task, 300, TimeUnit.SECONDS);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Some of the timeouts are VERY questionable, but I kept them as is to make this purely a refactor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks a little insane. However, this test looks to be exercising network failures, so, as an integration test, it might not be unreasonable for this to take multiple minutes to fail. But it's a unit test; so hopefully it doesn't actually take anywhere near that long. (Maybe 5m was used when writing the test against the real network? Then it was converted to a unit test, but the timeout wasn't fixed?)

Regardless, keeping it the same to keep this PR as a refactor sounds reasonable. You could optionally add a TODO to investigate whether this value still makes sense. (If you do, write the todo to apply to all non default timeouts.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added TODOs to all timeouts greater than 5 seconds with the exception of those that were already commented.

@schmidt-sebastian schmidt-sebastian changed the title Storage: Added TestUtil.await Storage: Add TestUtil.await Jun 3, 2019
Copy link
Member

@rsgowman rsgowman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

200+ lines deleted. Nice.

Thread.sleep(1);
}

org.junit.Assert.fail();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about org.junit.Assert.fail("Timeout occurred"); or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Thread.sleep(1);
}

org.junit.Assert.fail();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've imported org.junit.Assert, I think you could just write this as Assert.fail();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and done!

return;
}
Thread.sleep(1);
TestUtil.await(task, 300, TimeUnit.SECONDS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks a little insane. However, this test looks to be exercising network failures, so, as an integration test, it might not be unreasonable for this to take multiple minutes to fail. But it's a unit test; so hopefully it doesn't actually take anywhere near that long. (Maybe 5m was used when writing the test against the real network? Then it was converted to a unit test, but the timeout wasn't fixed?)

Regardless, keeping it the same to keep this PR as a refactor sounds reasonable. You could optionally add a TODO to investigate whether this value still makes sense. (If you do, write the todo to apply to all non default timeouts.)

Assert.fail();
} catch (RuntimeExecutionException e) {
Assert.assertEquals(taskException.get().getCause(), e.getCause().getCause());
// Task failed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd probably get rid of these 'task failed' comments (here and below). Optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But.... how will anyone understand this sophisticated logic? :) Removed.

Thread.sleep(1);
}
Assert.fail();
TestUtil.await(task, 20, TimeUnit.SECONDS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this ^. This non-default timeout is documented, so we know it's deliberate and meaningful. We should (eventually) do that for all of them. You could even enforce that by changing TestUtil.await(Task, int, TimeUnit) to TestUtil.await(Task, int, TimeUnit, String reasonWhyWereNotUsingTheDefault) (which is a little odd, but would be pretty effective.) Or, since I see this same reason is used again below, TestUtil.awaitFairnessBug(task)

(Aside: 20s timeout in a "unit" test is questionable.)

No action required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged, but left the timeouts and the comment as is for now.

@schmidt-sebastian schmidt-sebastian merged commit 74a0996 into master Jun 4, 2019
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/await branch June 5, 2019 20:37
@firebase firebase locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants