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

Improve companion tests / global, singleton state #3545

Open
Tracked by #3284
mifi opened this issue Mar 8, 2022 · 0 comments
Open
Tracked by #3284

Improve companion tests / global, singleton state #3545

mifi opened this issue Mar 8, 2022 · 0 comments
Labels
Companion The auth server (for Instagram, GDrive, etc) and upload proxy (for S3)

Comments

@mifi
Copy link
Contributor

mifi commented Mar 8, 2022

A pain point while working with companion is that the jest tests are not independent and they share state.
This makes tests nondeterministic, flaky and sometimes makes changing one test cause other unrelated tests also fail. I believe that unit tests should never depend on each other so this is something we should fix.

This is partly being worked around in getServer (mockserver.js) which calls jest.resetModules every time a server is created.

Obstacles and things to fix in order to make tests independent:

  • getServer return value is being shared between multiple tests. Example here:
    // the order in which getServer is called matters because, once an env is passed,
  • environment variables are being set on process.env in tests (but not cleared after being set, causing obscure bugs in unrelated tests when changing something). I think we should instead parameterise env variables instead of pulling them from process.env and assigning process.env.COMPANION_XYZ in every test.
  • metrics middleware has global state and crashes if initialised twice
  • emitter state is stored globally (singleton) and cannot be changed after initialisation
  • logger state is stored globally (singleton) and cannot be changed after initialisation - a user hit this when they wanted multiple companions running: How to use multiple S3 buckets #3214 (comment)
  • redis singleton
  • ... possibly more

I guess the cleanest would be to not have any global state at all, and always sent state that is needed into the classes and functions that need them. However it could become tedious with logger.

@mifi mifi added Architecture Companion The auth server (for Instagram, GDrive, etc) and upload proxy (for S3) labels Mar 8, 2022
@arturi arturi removed the Triage label Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Companion The auth server (for Instagram, GDrive, etc) and upload proxy (for S3)
Projects
None yet
Development

No branches or pull requests

2 participants