๐ (ci): Make runner-dispatch tests isolation-safe
Changes
3 files changed, +28 -9
MODIFY
src/test/java/de/workaround/ci/OrgScopedRunnerTest.java
+3 -0
@@ -12,6 +12,7 @@
12
12
import de.workaround.model.Organisation;
13
13
import de.workaround.model.Repository;
14
14
import de.workaround.model.User;
15
+import io.quarkus.test.TestTransaction;
15
16
import io.quarkus.test.junit.QuarkusTest;
16
17
import jakarta.inject.Inject;
17
18
import jakarta.transaction.Transactional;
@@ -42,6 +43,7 @@
42
43
Organisation.Repo organisations;
43
44
44
45
@Test
46
+ @TestTransaction
45
47
void orgScopedRunnerRunsItsOrgReposButNotOthers()
46
48
{
47
49
User admin = persistUser("org-admin-" + shortId());
@@ -56,6 +58,7 @@
56
58
}
57
59
58
60
@Test
61
+ @TestTransaction
59
62
void orgScopedRunnerIdlesWhenOnlyOtherOwnersHaveWork()
60
63
{
61
64
User admin = persistUser("org-admin2-" + shortId());
MODIFY
src/test/java/de/workaround/ci/ScopedRunnerTest.java
+4 -0
@@ -11,6 +11,7 @@
11
11
import de.workaround.model.ActionTask;
12
12
import de.workaround.model.Repository;
13
13
import de.workaround.model.User;
14
+import io.quarkus.test.TestTransaction;
14
15
import io.quarkus.test.junit.QuarkusTest;
15
16
import jakarta.inject.Inject;
16
17
import jakarta.transaction.Transactional;
@@ -41,6 +42,7 @@
41
42
ActionTask.Repo tasks;
42
43
43
44
@Test
45
+ @TestTransaction
44
46
void repoScopedRunnerSkipsOtherReposTasks()
45
47
{
46
48
User admin = persistUser("sr-admin-" + shortId());
@@ -57,6 +59,7 @@
57
59
}
58
60
59
61
@Test
62
+ @TestTransaction
60
63
void repoScopedRunnerGetsNothingWhenOnlyOtherReposHaveWork()
61
64
{
62
65
User admin = persistUser("sr-admin2-" + shortId());
@@ -69,6 +72,7 @@
69
72
}
70
73
71
74
@Test
75
+ @TestTransaction
72
76
void instanceRunnerClaimsAnyRepo()
73
77
{
74
78
User admin = persistUser("sr-admin3-" + shortId());
MODIFY
src/test/java/de/workaround/ci/SecretDeliveryTest.java
+21 -9
@@ -55,8 +55,8 @@
55
55
@Test
56
56
void claimedTaskReceivesRepoSecretsAndVariables()
57
57
{
58
- RunnerRegistrationService.RegisteredRunner reg = registerRunner();
59
- seed("sd-a");
58
+ Repository repo = seed("sd-a");
59
+ RunnerRegistrationService.RegisteredRunner reg = registerRunner(repo);
60
60
61
61
TaskDispatchService.Fetched fetched = dispatch.fetch(reg.runner().uuid, reg.plaintext());
62
62
@@ -68,8 +68,8 @@
68
68
@Test
69
69
void undecryptableSecretIsDroppedNotLeaked()
70
70
{
71
- RunnerRegistrationService.RegisteredRunner reg = registerRunner();
72
- seedWithCorruptSecret("sd-c");
71
+ Repository repo = seedWithCorruptSecret("sd-c");
72
+ RunnerRegistrationService.RegisteredRunner reg = registerRunner(repo);
73
73
74
74
TaskDispatchService.Fetched fetched = dispatch.fetch(reg.runner().uuid, reg.plaintext());
75
75
@@ -82,7 +82,8 @@
82
82
@Test
83
83
void emptyFetchCarriesNoSecrets()
84
84
{
85
- RunnerRegistrationService.RegisteredRunner reg = registerRunner();
85
+ Repository repo = emptyRepo("sd-b");
86
+ RunnerRegistrationService.RegisteredRunner reg = registerRunner(repo);
86
87
87
88
TaskDispatchService.Fetched fetched = dispatch.fetch(reg.runner().uuid, reg.plaintext());
88
89
@@ -91,14 +92,23 @@
91
92
assertTrue(fetched.vars().isEmpty());
92
93
}
93
94
94
- private RunnerRegistrationService.RegisteredRunner registerRunner()
95
+ // scope the runner to the test's own repo so the global dispatch queue (other tests' committed
96
+ // pending tasks) can't be claimed instead
97
+ private RunnerRegistrationService.RegisteredRunner registerRunner(Repository repo)
95
98
{
96
- String token = runnerService.createRegistrationToken(persistUser("sd-admin-" + shortId())).plaintext();
99
+ String token = runnerService.createRegistrationToken(persistUser("sd-admin-" + shortId()), repo).plaintext();
97
100
return runnerService.register(token, "sd-runner", List.of(), "v4.0.0", false);
98
101
}
99
102
100
103
@Transactional
101
- void seed(String repoName)
104
+ Repository emptyRepo(String repoName)
105
+ {
106
+ return repositories.create(persistUser(repoName + "-" + shortId()), repoName, Repository.Visibility.PUBLIC,
107
+ null);
108
+ }
109
+
110
+ @Transactional
111
+ Repository seed(String repoName)
102
112
{
103
113
User owner = persistUser(repoName + "-" + shortId());
104
114
Repository repo = repositories.create(owner, repoName, Repository.Visibility.PUBLIC, null);
@@ -130,10 +140,11 @@
130
140
task.name = "build";
131
141
task.payload = "on: push";
132
142
task.persist();
143
+ return repo;
133
144
}
134
145
135
146
@Transactional
136
- void seedWithCorruptSecret(String repoName)
147
+ Repository seedWithCorruptSecret(String repoName)
137
148
{
138
149
User owner = persistUser(repoName + "-" + shortId());
139
150
Repository repo = repositories.create(owner, repoName, Repository.Visibility.PUBLIC, null);
@@ -165,6 +176,7 @@
165
176
task.name = "build";
166
177
task.payload = "on: push";
167
178
task.persist();
179
+ return repo;
168
180
}
169
181
170
182
@Transactional