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

(PC-5740) feat: clear react-query cache after each test file #241

Merged
merged 2 commits into from Dec 15, 2020

Conversation

Giregm
Copy link
Contributor

@Giregm Giregm commented Dec 14, 2020

Link to JIRA ticket: https://passculture.atlassian.net/browse/PC-5740

Before After
image image

Stratégie

Jest conseille yarn jest --detectOpenHandles --runInBand pour détecter les fuites, faire cela sur notre répo donnera le même résultat qu'en CI: les tests finis en ~70s et la commande qui continue de tourner dans le vide 5min.

Pour identifier la source j'ai lancé chaque test avec yarn jest <test_name> --detectOpenHandles
Et identifier ceux qui sont anormalement longs. (script)

...
Offer.test.tsx
---- Time it took to do this test:  310.40674090385437s

...

BusinessModule.test.tsx
---- Time it took to do this test:  303.2644901275635s

CodePushButton.test.tsx
---- Time it took to do this test:  3.6475729942321777s

AcceptCgu.test.tsx
---- Time it took to do this test:  3.421457290649414s

...

ExclusivityModule.test.tsx
---- Time it took to do this test:  2.934148073196411s

useHomeAlgoliaModules.test.ts
---- Time it took to do this test:  302.83230209350586s

highlightLinks.test.tsx
---- Time it took to do this test:  3.235327959060669s

...
...

Certains tests prennent 5minutes lancés tout seuls
Ces tests partagent entre autre l'utilisation de react-query

Quelques recherches dans ce sens et je tombe sur une issue: react-query (n° 270)
On y lit notamment

Right now it’s recommended to clear the query cache after each test, so what if the timeout or rerender checked to see if the query still exists in the cache or is mounted. Would that work?

Bingo. (NB: 5min <-> durée de vie par défaut du cache, possible que ce ne soit pas une coïncidence)

@Giregm Giregm added WIP 🚧 Work in Progress and removed WIP 🚧 Work in Progress labels Dec 14, 2020
Copy link
Contributor

@antoinewg antoinewg left a comment

Choose a reason for hiding this comment

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

bien joué 💯
on garde le script ?

@Giregm Giregm merged commit bd2faba into master Dec 15, 2020
@Giregm Giregm deleted the PC-5740-find-jest-leaks branch December 15, 2020 08:42
@Giregm
Copy link
Contributor Author

Giregm commented Dec 15, 2020

bien joué 💯
on garde le script ?

Merci !
Je l'ai mis car si le problème arrive à nouveau ça peut être utile !
Et puis on ne perd rien à l'avoir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants