Skip to content
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

[Rollup] Fix component integration tests #121144

Merged
merged 7 commits into from
Dec 16, 2021

Conversation

sebelga
Copy link
Contributor

@sebelga sebelga commented Dec 13, 2021

In this PR I have fixed the rollup CIT tests which were still using timeout and not jest.useFakeTimers. I've also remove all use of nextTick in the different test files.

Fixes #70043
Fixes #69783

@sebelga sebelga added Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.17.0 v8.0.0 v8.1.0 labels Dec 13, 2021
@sebelga sebelga marked this pull request as ready for review December 14, 2021 19:03
@sebelga sebelga requested review from a team as code owners December 14, 2021 19:03
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-management (Team:Stack Management)

@sebelga sebelga requested a review from yuliacech December 14, 2021 19:03
@@ -159,7 +159,7 @@ export class JobCreateUi extends Component {
requestIndexPatternValidation = debounce((resetDefaults = true) => {
const indexPattern = this.getIndexPattern();

const lastIndexPatternValidationTime = (this.lastIndexPatternValidationTime = Date.now());
const lastIndexPatternValidationIdx = ++this.lastIndexPatternValidationIdx;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not relying on the Date for this as we can simply use an incremental counter. Better for the tests too.

@sebelga sebelga added the release_note:skip Skip the PR/issue when compiling release notes label Dec 14, 2021
@sebelga
Copy link
Contributor Author

sebelga commented Dec 15, 2021

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
rollup 129.0KB 129.0KB -13.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

form.setInputValue('rollupJobName', JOB_TO_CREATE.id);
await form.setInputValue('rollupIndexPattern', JOB_TO_CREATE.indexPattern, true);
form.setInputValue('rollupIndexName', JOB_TO_CREATE.rollupIndex);
act(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure what's the difference between await act(async () => { and this version without await and async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we want to be as synchronous as possible and use act(). In some cases using the synchronous version is not enough because, for example, clicking a button triggers a promise that resolves on the next tick and then updates the state. The way to wait for that next tick is to use the async version await act(async() => {...}).

I usually start with the sync version and if the state does not update I change to the async one. With component integration tests it is not always easy to remember all the moving parts occuring after changing a field value or clicking a button.

@@ -29,11 +26,16 @@ describe('Cloning a rollup job through create job wizard', () => {
let startMock;

beforeAll(() => {
jest.useFakeTimers();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering why we would need fakeTimers if we don't use any of advanceTimersByTime or runAllTimers, would you mind explaining?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to have the guarantee that there aren't any timeout running in the tests. We are not using jest for isolated unit tests but for component integration tests which load all the npm dependencies which could potentially use timeouts. And we don't want them in our test.

By adding this on top of our tests we are removing any risk of timing out so I would recommend to declare jest.useFakeTimers(); to every component integration test file.

await new Promise((res) => setTimeout(res, 750));

// There is a 500 timeout before receiving the response.
// To be investigated, this is the only app requiring a timeout to avoid a "weird flicker";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please open an issue for that (if none exist yet), this seems like a good candidate for tech debt work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done (#121386)

Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Amazing work, @sebelga! Really nice seeing those flaky tests addressed 👍
I left a couple of questions in the code, just wondering if the use of fakeTimers is indeed necessary for all tests.

Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Thank you so much for your explanations, @sebelga! Happy to see this PR get merged.
I also think it would be great to have your great testing knowledge documented somewhere :)

@sebelga sebelga merged commit 20ab0ef into elastic:main Dec 16, 2021
@sebelga
Copy link
Contributor Author

sebelga commented Dec 16, 2021

Thanks for the review @yuliacech ! 👍

sebelga added a commit to sebelga/kibana that referenced this pull request Dec 16, 2021
sebelga added a commit to sebelga/kibana that referenced this pull request Dec 16, 2021
sebelga added a commit that referenced this pull request Dec 18, 2021
@sebelga sebelga deleted the tests/unskip-cit-rollup branch December 23, 2021 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.17.0 v8.0.0 v8.1.0
Projects
None yet
6 participants