-
Notifications
You must be signed in to change notification settings - Fork 56
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
Use nox to test different environments #1245
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
Ouch, this was quite nasty 🤪. I now went another route by keeping |
tests/conftest.py
Outdated
migrations = sorted(migrations_path.glob("*.sql")) | ||
last_migration = migrations[-1] | ||
if "_post_" in last_migration.name: | ||
migrations.remove(last_migration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not right.
1/ There may be multiple post_migrations
2/ maybe the last release was 3.4, the current release we're working on will be 3.5, and 3.4 had no migrations and the last migrations are the ones for 3.3, and in that case we don't want to test 3.5 without the post-migrations of 3.3. The only post-migrations we want to skip are those that haven't been released yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Sorry, I should have made this a draft. It's just temporary, but I think I will fetch the latest tag in the nox session and then provide it as an option to pytest (seems to me more like part of the environment).
@ewjoachim I finally got it working. Some tests of |
noxfile.py
Outdated
shutil.copytree(base_path / "tests", temp_path / "tests") | ||
shutil.copy(base_path / "pyproject.toml", temp_path / "pyproject.toml") | ||
shutil.copy(base_path / "poetry.lock", temp_path / "poetry.lock") | ||
os.chdir(temp_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.MonkeyPatch.chdir so it will be revrted at the end of the test
EDIT: ah sorry I was thinking pytest but this is a Nexfile. Plus, you're fixing it in the next commit.
|
||
|
||
@nox.session | ||
def stable_version_without_post_migration(session: nox.Session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's funny because in the end the noxfile solution ended up being not that far from my original solution. Of course, it's an excellent idea to use nox so that we don't have to bother with creating our venvs ourselves. But in the end, if you want to be sure to run exactly the tests you want with the procrastinate you want, you need a tmpdir, and run things inside.
- In my solution, we use the same pytest process for everything, and it calls subprocesses for procrastinate. Whereas in your solution, we call distinct pytest subprocesses for each of the 3 cases.
- In my solution, we don't need to install anything else than procrastinate in the venv, whereas in your solution, we install pytest in all venvs.
- In your solution, we keep existing acceptance tests. In my solution, we need to rewrite them.
I don't think any approach outshines the other one at 100%, and I'd be comfortable with either. We're just not going to end up with the same set of problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to adapt the CI of course. Otherwise, I'm looking forward to discussing this with you in pair :)
- `xx.yy.zz` is the version of Procrastinate the migration script can be applied to. | ||
- `ab` is the migration script's serial number, `01` being the first number in the | ||
series. | ||
- `pre` / `post`: indicates wether the migration should be applied before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `pre` / `post`: indicates wether the migration should be applied before | |
- `pre` / `post`: indicates whether the migration should be applied before |
(my own mistake)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running locally: yes, I think we end up having problems due to tests acceptance added by 3.x not compatible with 2.x :/
series. | ||
- `pre` / `post`: indicates wether the migration should be applied before | ||
upgrading the code (`pre`) or after upgrading the code (`post`) in the context | ||
of a blue-green deployment. On old migrations, if `pre` or `post` is not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of a blue-green deployment. On old migrations, if `pre` or `post` is not | |
of a blue-green deployment (see below). On old migrations, if `pre` or `post` is not |
$ ... | ||
``` | ||
|
||
3. Upgrade your code to the new Procrastinate version. | ||
4. Start all the services. | ||
|
||
This, as you've noticed, only works if you're able to stop the services. | ||
|
||
## The safer way, without service interruption |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## The safer way, without service interruption | |
## The safer way, without service interruption (a.k.a "blue-green") |
you will have to interrupt the service or write custom migrations. | ||
::: | ||
If you need to ensure service continuity, you'll need to make intermediate upgrades. | ||
Basically, you'll need to stop at every version that provides migrations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, you'll need to stop at every version that provides migrations. | |
Basically, you'll need to stop at every version that provides migrations. | |
Repeat the following for all versions: | |
1. Apply pre-migrations | |
2. Deploy version to your system | |
3. Apply post-migrations | |
4. Repeat until you reach the desired version | |
If multiple versions in a row don't have migrations, you can deploy the last of them without going through intermediate ones. Pre-migrations are only guaranteed to work on the immediately previous version. Post-migrations are only guaranteed to work on their own version. |
shutil.copy(base_path / "pyproject.toml", temp_path / "pyproject.toml") | ||
shutil.copy(base_path / "poetry.lock", temp_path / "poetry.lock") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we export the deps, why do we need pyproject.toml ? (and vice versa)
tests/utils.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is now unused?
50aba0c
to
c347eed
Compare
…G status just yet
11b94c9
to
da7e37b
Compare
CONTRIBUTING.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@medihack this is the file where most of the doc we discussed was added
da7e37b
to
05e182b
Compare
05e182b
to
355da01
Compare
Congratulations @medihack ! |
I started integrating
nox
to solve our problem with the different environments (latest stable and current version). This is not finished yet, but I have a plan for how to do it.I also added a custom option to pytest named
--skip-post-migration
to skip the last post-migration file when setting up the database. But this reveals more problems with my pre-/post-migrations that I understand but don’t know how to solve. The main problem is that without the post-migration we are already usingprocrastinate_job_status_v1
in the current version on multiple occasions (for example, in queries.sql), but theprocrastinate_jobs
table still usesprocrastinate_job_status
(without “_v1”) as this conversion is part of the post-migration. But there is no way to do this conversion in the pre-migration as this would break the latest stable version 😞.