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

Make sure multi-db tests are passing #2813

Merged
merged 6 commits into from
Apr 25, 2023
Merged

Conversation

dmos62
Copy link
Contributor

@dmos62 dmos62 commented Apr 13, 2023

Related #2007

Some maintenance on multi-db tests, in preparation for db-switching functionality on frontend. Biggest change is reenabling tests that were marked for skipping for some reason.

Also did basic smoke checking locally.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@dmos62 dmos62 added the work: backend Related to Python, Django, and simple SQL label Apr 13, 2023
@dmos62 dmos62 added this to the v0.1.2 milestone Apr 13, 2023
@dmos62 dmos62 requested a review from mathemancer April 13, 2023 15:13
Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

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

These tests assume that all DBs will be in the settings dict, and that we'll be able to modify the settings dict at runtime.

You can't modify the settings dict at runtime and expect things to work. They were flaky because of that (there's some kind of thread-dependence issue), and so I disabled them. I don't think they should be reenabled. The reason I didn't delete them outright was that I assume we'll want to make valid versions of these at some point.

https://docs.djangoproject.com/en/4.2/topics/settings/#altering-settings-at-runtime

NOTE: It's possible the thread-dependence thing goes away since we're no longer running tests in parallel, but I still don't think it's a good idea to use these tests.

@dmos62
Copy link
Contributor Author

dmos62 commented Apr 14, 2023

@mathemancer Do you have ideas about how to fix this? I can only think of redoing how we define user databases (which would be nice; should make an issue for that), but I'm not sure we have time for that right now.

I think it's important to test multi-db support, since we'll now have user-facing functionality dependent on that. Do you agree?

If we don't know how to fix this without making a project out of it, and the problem is only that these tests may have random false failures, maybe let's enable them and see what happens? If false failures do happen, and they mess with our workflow, we can then use that as justification to invest more time into this.

@mathemancer
Copy link
Contributor

@dmos62 I agree that now is not the time for modifying how we define DBs (though I also agree that we should fix that ASAP).

Couldn't we come up with a way to make the tests accurate to our current setup? I.e., we're not supporting modifying the settings dict at runtime (in memory) anyway, so why should we test that?

Wouldn't it be possible to just use a different settings file during testing, or even set up separate tests for this that use a multi-db settings file? What happens if they actually have multiple DBs defined in their settings file? I'm not actually sure what will happen to our tests, or these tests in that case.

@dmos62
Copy link
Contributor Author

dmos62 commented Apr 20, 2023

@mathemancer we've been setting up and tearing down the Django settings dict-like for every single test call though: https://github.com/centerofci/mathesar/blob/develop/mathesar/tests/conftest.py#L115. That doesn't make this pattern more supported by our stack, but it is pretty widespread in our testing suite.

Are you sure that fixing this now is warranted? Setting up a separate testing suite with its own Django configuration sounds like overkill (that's what would be required, if I'm not mistaken). I've tested running Django with multiple user dbs hardcoded in the config and it worked fine, for what it's worth.

@kgodey
Copy link
Contributor

kgodey commented Apr 20, 2023

Django docs for overriding settings in tests: https://docs.djangoproject.com/en/4.2/topics/testing/tools/#overriding-settings, just in case it helps.

@mathemancer
Copy link
Contributor

@mathemancer we've been setting up and tearing down the Django settings dict-like for every single test call though: https://github.com/centerofci/mathesar/blob/develop/mathesar/tests/conftest.py#L115. That doesn't make this pattern more supported by our stack, but it is pretty widespread in our testing suite.

Are you sure that fixing this now is warranted? Setting up a separate testing suite with its own Django configuration sounds like overkill (that's what would be required, if I'm not mistaken). I've tested running Django with multiple user dbs hardcoded in the config and it worked fine, for what it's worth.

I think turning these tests back off would be far preferable to setting a trap in our testing suite to forget about. We'd inevitably end up building more on top of the same misguided setup, making the problem worse and worse.

Django docs for overriding settings in tests: https://docs.djangoproject.com/en/4.2/topics/testing/tools/#overriding-settings, just in case it helps.

Unless I'm misunderstanding, that page indicates that using those methods on DATABASES will not have the expected effect.

@dmos62
Copy link
Contributor Author

dmos62 commented Apr 21, 2023

@mathemancer

a trap in our testing suite to forget about

We have an issue to track this, and when we refactor how we define user dbs, all of this will have to be changed, so these few tests, and whatever tests we derive from them, aren't something we can forget, unless we forget to fix user db definition.

As for it being a trap, I'm still not sure what the problem is here, but you mention it being about multi-threading, so how about we restrict these tests to running in the same pytest-xdist runner?

Or, better yet, since we don't use xdist at the moment, how about we create an issue for reenabling pytest-xdist and make it blocked on #2816?

To be clear for why I'm inclined not to simply disable the tests, I'll repeat that I think it's important to test multi-db support, since we'll now have user-facing functionality dependent on that.

@kgodey
Copy link
Contributor

kgodey commented Apr 21, 2023

when we refactor how we define user dbs

Why are we refactoring how we define user DBs?

Also here's a relevant SO answer, also in case it helps

@dmos62
Copy link
Contributor Author

dmos62 commented Apr 24, 2023

Me and @mathemancer resolved this in sync:

  1. Add code comments in the tests, explaining the context and possibility for false failures;
  2. Create an issue for reenabling pytest-xdist and make it blocked on Redo how we define user databases #2816;
  3. Merge this.

@dmos62
Copy link
Contributor Author

dmos62 commented Apr 24, 2023

@kgodey does the issue description in #2816 provide enough context? We can continue discussing there, if needed.

@kgodey
Copy link
Contributor

kgodey commented Apr 24, 2023

@dmos62 I looked at #2816 but there's not enough context there. I don't understand the underlyng problem, and so I can't evaluate whether redoing the way we define user DBs the only/best solution to it. It might be better to keep the GitHub issue focused on explaining the problem rather than presuming the solution.

@dmos62
Copy link
Contributor Author

dmos62 commented Apr 24, 2023

@kgodey I'll respond in #2816.

@dmos62 dmos62 enabled auto-merge April 25, 2023 13:21
@dmos62 dmos62 added this pull request to the merge queue Apr 25, 2023
Merged via the queue into develop with commit dc8d5a3 Apr 25, 2023
17 checks passed
@dmos62 dmos62 deleted the backend-multi-db-support branch April 25, 2023 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work: backend Related to Python, Django, and simple SQL
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants