Skip to content

Commit bc59ac6

Browse files
committed
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.
1 parent 671ccdf commit bc59ac6

File tree

3 files changed

+147
-6
lines changed

3 files changed

+147
-6
lines changed
Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/usr/bin/env clitest --v0
22

3-
$ gel instance destroy -I watch_test --force
3+
$ gel instance destroy -I watch_test0 --force
44
%EXIT any
55
*
66

77
using tempdir;
88

9-
using new dir "watch_test";
9+
using new dir "watch_test0";
1010

11-
$ gel project init --instance=watch_test --non-interactive
11+
$ gel project init --instance=watch_test0 --non-interactive
12+
*
13+
14+
# Create another branch for tests
15+
$ gel branch create other
1216
*
1317

1418
$ find .
@@ -21,16 +25,47 @@ background {
2125
}
2226

2327
background {
24-
$ gel instance logs -I watch_test --follow --tail 10
28+
$ gel instance logs -I watch_test0 --follow --tail 10
2529
%EXIT any
2630
*
2731
}
2832

2933
# Give it a second to start up
3034
$ sleep 1
3135

32-
# Project is locked, so we can't switch to another branch
33-
$ gel branch switch --create --empty other
36+
# Cannot start another watch for the same project
37+
$ gel watch --migrate
38+
%EXIT 1
39+
*
40+
! gel error: Could not acquire lock %{GREEDYDATA}
41+
42+
# Project is locked, so we can't manipulate branches
43+
$ gel branch switch other
44+
%EXIT 1
45+
*
46+
! gel error: Could not acquire lock %{GREEDYDATA}
47+
48+
$ gel branch switch --create --empty foo
49+
%EXIT 1
50+
*
51+
! gel error: Could not acquire lock %{GREEDYDATA}
52+
53+
$ gel branch wipe main
54+
%EXIT 1
55+
*
56+
! gel error: Could not acquire lock %{GREEDYDATA}
57+
58+
$ gel branch rebase other
59+
%EXIT 1
60+
*
61+
! gel error: Could not acquire lock %{GREEDYDATA}
62+
63+
$ gel branch merge other
64+
%EXIT 1
65+
*
66+
! gel error: Could not acquire lock %{GREEDYDATA}
67+
68+
$ gel branch drop other
3469
%EXIT 1
3570
*
3671
! gel error: Could not acquire lock %{GREEDYDATA}
@@ -94,3 +129,14 @@ $ sleep 1
94129
$ gel query "select schema::Migration {*} filter .generated_by =
95130
schema::MigrationGeneratedBy.DevMode;"
96131
*
132+
133+
# Project is locked, so we can't overwrite the migrations
134+
$ gel migration extract
135+
%EXIT 1
136+
*
137+
! gel error: Could not acquire lock %{GREEDYDATA}
138+
139+
$ gel migration edit
140+
%EXIT 1
141+
*
142+
! gel error: Could not acquire lock %{GREEDYDATA}

tests/scripts/project/watch1.cli

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env clitest --v0
2+
3+
$ gel instance destroy -I watch_test1 --force
4+
%EXIT any
5+
*
6+
7+
using tempdir;
8+
9+
using new dir "watch_test1";
10+
11+
$ gel project init --instance=watch_test1 --non-interactive
12+
*
13+
14+
$ find .
15+
*
16+
17+
background {
18+
$ gel watch --migrate --verbose
19+
%EXIT any
20+
*
21+
}
22+
23+
background {
24+
$ gel instance logs -I watch_test1 --follow --tail 10
25+
%EXIT any
26+
*
27+
}
28+
29+
# Give it a second to start up
30+
$ sleep 1
31+
32+
$ gel instance backup -I watch_test1 --non-interactive
33+
*
34+
35+
# Project is locked, so we can't manipulate branches
36+
$ gel instance restore -I test --latest --non-interactive
37+
%EXIT 1
38+
*
39+
! gel error: Could not acquire lock %{GREEDYDATA}

tests/scripts/project/watch2.cli

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env clitest --v0
2+
3+
$ gel instance destroy -I watch_test2 --force
4+
%EXIT any
5+
*
6+
7+
using tempdir;
8+
9+
using new dir "watch_test2";
10+
11+
$ gel project init --instance=watch_test2 --non-interactive
12+
*
13+
14+
$ find .
15+
*
16+
17+
# Create a git repo for tests
18+
$ git init -b main
19+
*
20+
21+
$ git add dbschema
22+
*
23+
24+
$ git commit -m 'Empty schema'
25+
*
26+
27+
$ git checkout -b user
28+
*
29+
30+
$ echo "module test {
31+
type User {
32+
name: str;
33+
}
34+
}" > dbschema/default.gel
35+
*
36+
37+
$ git add dbschema/default.gel
38+
*
39+
40+
$ git commit -m 'Add User'
41+
*
42+
43+
background {
44+
$ gel watch --migrate --verbose
45+
%EXIT 1
46+
*
47+
! gel error: Current git branch (main) is different from the branch used to start watch mode (user), exiting.
48+
}
49+
50+
# Give it a second to start up
51+
$ sleep 1
52+
53+
$ git checkout main
54+
*
55+
56+
$ sleep 5

0 commit comments

Comments
 (0)