Skip to content

Commit 27acd32

Browse files
committed
Add timeouts to tests
1 parent df23617 commit 27acd32

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

Diff for: .github/workflows/ci.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
jobs:
1212
fmt:
1313
runs-on: windows-latest
14+
timeout-minutes: 10
1415
steps:
1516
- uses: actions/checkout@v4
1617
- name: Setup dotnet
@@ -26,6 +27,7 @@ jobs:
2627

2728
test:
2829
runs-on: windows-latest
30+
timeout-minutes: 10
2931
steps:
3032
- uses: actions/checkout@v4
3133
- name: Setup dotnet
@@ -41,6 +43,7 @@ jobs:
4143

4244
build:
4345
runs-on: windows-latest
46+
timeout-minutes: 10
4447
steps:
4548
- uses: actions/checkout@v4
4649
- name: Setup dotnet

Diff for: .github/workflows/release.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ permissions:
1818
jobs:
1919
release:
2020
runs-on: ${{ github.repository_owner == 'coder' && 'windows-latest-16-cores' || 'windows-latest' }}
21+
timeout-minutes: 15
2122

2223
steps:
2324
- uses: actions/checkout@v4

Diff for: Tests.App/Services/CredentialManagerTest.cs

+22-15
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ public async Task EndToEnd(CancellationToken ct)
7979
finally
8080
{
8181
// In case something goes wrong, make sure to clean up.
82-
await credentialBackend.DeleteCredentials(CancellationToken.None);
82+
using var cts = new CancellationTokenSource();
83+
cts.CancelAfter(15_000);
84+
await credentialBackend.DeleteCredentials(cts.Token);
8385
}
8486
}
8587

8688
[Test(Description = "Test SetCredentials with invalid URL or token")]
87-
public void SetCredentialsInvalidUrlOrToken()
89+
[CancelAfter(30_000)]
90+
public void SetCredentialsInvalidUrlOrToken(CancellationToken ct)
8891
{
8992
var credentialBackend = new Mock<ICredentialBackend>(MockBehavior.Strict);
9093
var apiClientFactory = new Mock<ICoderApiClientFactory>(MockBehavior.Strict);
@@ -107,13 +110,14 @@ public void SetCredentialsInvalidUrlOrToken()
107110
foreach (var (url, token, expectedMessage) in cases)
108111
{
109112
var ex = Assert.ThrowsAsync<ArgumentException>(() =>
110-
manager.SetCredentials(url, token, CancellationToken.None));
113+
manager.SetCredentials(url, token, ct));
111114
Assert.That(ex.Message, Does.Contain(expectedMessage));
112115
}
113116
}
114117

115118
[Test(Description = "Invalid server buildinfo response")]
116-
public void InvalidServerBuildInfoResponse()
119+
[CancelAfter(30_000)]
120+
public void InvalidServerBuildInfoResponse(CancellationToken ct)
117121
{
118122
var credentialBackend = new Mock<ICredentialBackend>(MockBehavior.Strict);
119123
var apiClient = new Mock<ICoderApiClient>(MockBehavior.Strict);
@@ -126,7 +130,7 @@ public void InvalidServerBuildInfoResponse()
126130
// Attempt a set.
127131
var manager = new CredentialManager(credentialBackend.Object, apiClientFactory.Object);
128132
var ex = Assert.ThrowsAsync<InvalidOperationException>(() =>
129-
manager.SetCredentials(TestServerUrl, TestApiToken, CancellationToken.None));
133+
manager.SetCredentials(TestServerUrl, TestApiToken, ct));
130134
Assert.That(ex.Message, Does.Contain("Could not connect to or verify Coder server"));
131135

132136
// Attempt a load.
@@ -136,12 +140,13 @@ public void InvalidServerBuildInfoResponse()
136140
CoderUrl = TestServerUrl,
137141
ApiToken = TestApiToken,
138142
});
139-
var cred = manager.LoadCredentials(CancellationToken.None).Result;
143+
var cred = manager.LoadCredentials(ct).Result;
140144
Assert.That(cred.State, Is.EqualTo(CredentialState.Invalid));
141145
}
142146

143147
[Test(Description = "Invalid server version")]
144-
public void InvalidServerVersion()
148+
[CancelAfter(30_000)]
149+
public void InvalidServerVersion(CancellationToken ct)
145150
{
146151
var credentialBackend = new Mock<ICredentialBackend>(MockBehavior.Strict);
147152
var apiClient = new Mock<ICoderApiClient>(MockBehavior.Strict);
@@ -157,7 +162,7 @@ public void InvalidServerVersion()
157162
// Attempt a set.
158163
var manager = new CredentialManager(credentialBackend.Object, apiClientFactory.Object);
159164
var ex = Assert.ThrowsAsync<ArgumentException>(() =>
160-
manager.SetCredentials(TestServerUrl, TestApiToken, CancellationToken.None));
165+
manager.SetCredentials(TestServerUrl, TestApiToken, ct));
161166
Assert.That(ex.Message, Does.Contain("not within required server version range"));
162167

163168
// Attempt a load.
@@ -167,12 +172,13 @@ public void InvalidServerVersion()
167172
CoderUrl = TestServerUrl,
168173
ApiToken = TestApiToken,
169174
});
170-
var cred = manager.LoadCredentials(CancellationToken.None).Result;
175+
var cred = manager.LoadCredentials(ct).Result;
171176
Assert.That(cred.State, Is.EqualTo(CredentialState.Invalid));
172177
}
173178

174179
[Test(Description = "Invalid server user response")]
175-
public void InvalidServerUserResponse()
180+
[CancelAfter(30_000)]
181+
public void InvalidServerUserResponse(CancellationToken ct)
176182
{
177183
var credentialBackend = new Mock<ICredentialBackend>(MockBehavior.Strict);
178184
var apiClient = new Mock<ICoderApiClient>(MockBehavior.Strict);
@@ -188,7 +194,7 @@ public void InvalidServerUserResponse()
188194
// Attempt a set.
189195
var manager = new CredentialManager(credentialBackend.Object, apiClientFactory.Object);
190196
var ex = Assert.ThrowsAsync<InvalidOperationException>(() =>
191-
manager.SetCredentials(TestServerUrl, TestApiToken, CancellationToken.None));
197+
manager.SetCredentials(TestServerUrl, TestApiToken, ct));
192198
Assert.That(ex.Message, Does.Contain("Could not connect to or verify Coder server"));
193199

194200
// Attempt a load.
@@ -198,12 +204,13 @@ public void InvalidServerUserResponse()
198204
CoderUrl = TestServerUrl,
199205
ApiToken = TestApiToken,
200206
});
201-
var cred = manager.LoadCredentials(CancellationToken.None).Result;
207+
var cred = manager.LoadCredentials(ct).Result;
202208
Assert.That(cred.State, Is.EqualTo(CredentialState.Invalid));
203209
}
204210

205211
[Test(Description = "Invalid username")]
206-
public void InvalidUsername()
212+
[CancelAfter(30_000)]
213+
public void InvalidUsername(CancellationToken ct)
207214
{
208215
var credentialBackend = new Mock<ICredentialBackend>(MockBehavior.Strict);
209216
var apiClient = new Mock<ICoderApiClient>(MockBehavior.Strict);
@@ -219,7 +226,7 @@ public void InvalidUsername()
219226
// Attempt a set.
220227
var manager = new CredentialManager(credentialBackend.Object, apiClientFactory.Object);
221228
var ex = Assert.ThrowsAsync<InvalidOperationException>(() =>
222-
manager.SetCredentials(TestServerUrl, TestApiToken, CancellationToken.None));
229+
manager.SetCredentials(TestServerUrl, TestApiToken, ct));
223230
Assert.That(ex.Message, Does.Contain("username is empty"));
224231

225232
// Attempt a load.
@@ -229,7 +236,7 @@ public void InvalidUsername()
229236
CoderUrl = TestServerUrl,
230237
ApiToken = TestApiToken,
231238
});
232-
var cred = manager.LoadCredentials(CancellationToken.None).Result;
239+
var cred = manager.LoadCredentials(ct).Result;
233240
Assert.That(cred.State, Is.EqualTo(CredentialState.Invalid));
234241
}
235242

0 commit comments

Comments
 (0)