From 23be5fa379bd71dfc12a79747f1cb1176ec7ef51 Mon Sep 17 00:00:00 2001 From: Victor Petrovykh Date: Tue, 27 May 2025 06:22:55 -0400 Subject: [PATCH] Add some more watch tests. Test that watch locks the project so that branch and migration editing commands cannot be executed. Test that restoring an instance during active watch cannot be done. Test that switching git branch during active watch terminates the watch. --- .../scripts/project/{watch.cli => watch0.cli} | 58 +++++++++++++++++-- tests/scripts/project/watch1.cli | 39 +++++++++++++ tests/scripts/project/watch2.cli | 56 ++++++++++++++++++ 3 files changed, 147 insertions(+), 6 deletions(-) rename tests/scripts/project/{watch.cli => watch0.cli} (60%) create mode 100644 tests/scripts/project/watch1.cli create mode 100644 tests/scripts/project/watch2.cli diff --git a/tests/scripts/project/watch.cli b/tests/scripts/project/watch0.cli similarity index 60% rename from tests/scripts/project/watch.cli rename to tests/scripts/project/watch0.cli index c09b04b86..90d31c25f 100644 --- a/tests/scripts/project/watch.cli +++ b/tests/scripts/project/watch0.cli @@ -1,14 +1,18 @@ #!/usr/bin/env clitest --v0 -$ gel instance destroy -I watch_test --force +$ gel instance destroy -I watch_test0 --force %EXIT any * using tempdir; -using new dir "watch_test"; +using new dir "watch_test0"; -$ gel project init --instance=watch_test --non-interactive +$ gel project init --instance=watch_test0 --non-interactive +* + +# Create another branch for tests +$ gel branch create other * $ find . @@ -21,7 +25,7 @@ background { } background { - $ gel instance logs -I watch_test --follow --tail 10 + $ gel instance logs -I watch_test0 --follow --tail 10 %EXIT any * } @@ -29,8 +33,39 @@ background { # Give it a second to start up $ sleep 1 -# Project is locked, so we can't switch to another branch -$ gel branch switch --create --empty other +# Cannot start another watch for the same project +$ gel watch --migrate +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} + +# Project is locked, so we can't manipulate branches +$ gel branch switch other +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} + +$ gel branch switch --create --empty foo +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} + +$ gel branch wipe main +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} + +$ gel branch rebase other +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} + +$ gel branch merge other +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} + +$ gel branch drop other %EXIT 1 * ! gel error: Could not acquire lock %{GREEDYDATA} @@ -108,3 +143,14 @@ $ sleep 1 $ gel query "select schema::Migration {*} filter .generated_by = schema::MigrationGeneratedBy.DevMode;" * + +# Project is locked, so we can't overwrite the migrations +$ gel migration extract +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} + +$ gel migration edit +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} diff --git a/tests/scripts/project/watch1.cli b/tests/scripts/project/watch1.cli new file mode 100644 index 000000000..cd7767f6c --- /dev/null +++ b/tests/scripts/project/watch1.cli @@ -0,0 +1,39 @@ +#!/usr/bin/env clitest --v0 + +$ gel instance destroy -I watch_test1 --force +%EXIT any +* + +using tempdir; + +using new dir "watch_test1"; + +$ gel project init --instance=watch_test1 --non-interactive +* + +$ find . +* + +background { + $ gel watch --migrate --verbose + %EXIT any + * +} + +background { + $ gel instance logs -I watch_test1 --follow --tail 10 + %EXIT any + * +} + +# Give it a second to start up +$ sleep 1 + +$ gel instance backup -I watch_test1 --non-interactive +* + +# Project is locked, so we can't manipulate branches +$ gel instance restore -I test --latest --non-interactive +%EXIT 1 +* +! gel error: Could not acquire lock %{GREEDYDATA} diff --git a/tests/scripts/project/watch2.cli b/tests/scripts/project/watch2.cli new file mode 100644 index 000000000..d526c533d --- /dev/null +++ b/tests/scripts/project/watch2.cli @@ -0,0 +1,56 @@ +#!/usr/bin/env clitest --v0 + +$ gel instance destroy -I watch_test2 --force +%EXIT any +* + +using tempdir; + +using new dir "watch_test2"; + +$ gel project init --instance=watch_test2 --non-interactive +* + +$ find . +* + +# Create a git repo for tests +$ git init -b main +* + +$ git add dbschema +* + +$ git commit -m 'Empty schema' +* + +$ git checkout -b user +* + +$ echo "module test { + type User { + name: str; + } +}" > dbschema/default.gel +* + +$ git add dbschema/default.gel +* + +$ git commit -m 'Add User' +* + +background { + $ gel watch --migrate --verbose + %EXIT 1 + * + ! gel error: Current git branch (main) is different from the branch used to start watch mode (user), exiting. +} + +# Give it a second to start up +$ sleep 1 + +$ git checkout main +* + +$ sleep 5