Skip to content

Commit 3ab8ebf

Browse files
Extend timeout and enforce usings (#12952)
Extend timeout and enforce usings
1 parent b1fdf27 commit 3ab8ebf

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected async Task SpaTemplateImplAsync(
4545
{
4646
Project = await ProjectFactory.GetOrCreateProject(key, Output);
4747

48-
var createResult = await Project.RunDotNetNewAsync(template, auth: usesAuth ? "Individual" : null, language: null, useLocalDb);
48+
using var createResult = await Project.RunDotNetNewAsync(template, auth: usesAuth ? "Individual" : null, language: null, useLocalDb);
4949
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", Project, createResult));
5050

5151
// We shouldn't have to do the NPM restore in tests because it should happen
@@ -61,40 +61,40 @@ protected async Task SpaTemplateImplAsync(
6161
Assert.Contains(".db", projectFileContents);
6262
}
6363

64-
var npmRestoreResult = await Project.RestoreWithRetryAsync(Output, clientAppSubdirPath);
64+
using var npmRestoreResult = await Project.RestoreWithRetryAsync(Output, clientAppSubdirPath);
6565
Assert.True(0 == npmRestoreResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm restore", Project, npmRestoreResult));
6666

67-
var lintResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run lint");
67+
using var lintResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run lint");
6868
Assert.True(0 == lintResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run lint", Project, lintResult));
6969

7070
if (template == "react" || template == "reactredux")
7171
{
72-
var testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run test");
72+
using var testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run test");
7373
Assert.True(0 == testResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run test", Project, testResult));
7474
}
7575

76-
var publishResult = await Project.RunDotNetPublishAsync();
76+
using var publishResult = await Project.RunDotNetPublishAsync();
7777
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", Project, publishResult));
7878

7979
// Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
8080
// The output from publish will go into bin/Release/netcoreapp3.0/publish and won't be affected by calling build
8181
// later, while the opposite is not true.
8282

83-
var buildResult = await Project.RunDotNetBuildAsync();
83+
using var buildResult = await Project.RunDotNetBuildAsync();
8484
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", Project, buildResult));
8585

8686
// localdb is not installed on the CI machines, so skip it.
8787
var shouldVisitFetchData = !useLocalDb;
8888

8989
if (usesAuth)
9090
{
91-
var migrationsResult = await Project.RunDotNetEfCreateMigrationAsync(template);
91+
using var migrationsResult = await Project.RunDotNetEfCreateMigrationAsync(template);
9292
Assert.True(0 == migrationsResult.ExitCode, ErrorMessages.GetFailedProcessMessage("run EF migrations", Project, migrationsResult));
9393
Project.AssertEmptyMigration(template);
9494

9595
if (shouldVisitFetchData)
9696
{
97-
var dbUpdateResult = await Project.RunDotNetEfUpdateDatabaseAsync();
97+
using var dbUpdateResult = await Project.RunDotNetEfUpdateDatabaseAsync();
9898
Assert.True(0 == dbUpdateResult.ExitCode, ErrorMessages.GetFailedProcessMessage("update database", Project, dbUpdateResult));
9999
}
100100
}
@@ -247,7 +247,7 @@ private void TestBasicNavigation(bool visitFetchData, bool usesAuth, IWebDriver
247247
browser.Equal("Weather forecast", () => browser.FindElement(By.TagName("h1")).Text);
248248

249249
// Asynchronously loads and displays the table of weather forecasts
250-
browser.Exists(By.CssSelector("table>tbody>tr"));
250+
browser.Exists(By.CssSelector("table>tbody>tr"), TimeSpan.FromSeconds(10));
251251
browser.Equal(5, () => browser.FindElements(By.CssSelector("p+table>tbody>tr")).Count);
252252
}
253253

src/Shared/E2ETesting/WaitAssert.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public static void Single(this IWebDriver driver, Func<IEnumerable> actualValues
4242
=> WaitAssertCore(driver, () => Assert.Single(actualValues()));
4343

4444
public static void Exists(this IWebDriver driver, By finder)
45-
=> WaitAssertCore(driver, () => Assert.NotEmpty(driver.FindElements(finder)));
45+
=> Exists(driver, finder, default);
46+
47+
public static void Exists(this IWebDriver driver, By finder, TimeSpan timeout)
48+
=> WaitAssertCore(driver, () => Assert.NotEmpty(driver.FindElements(finder)), timeout);
4649

4750
private static void WaitAssertCore(IWebDriver driver, Action assertion, TimeSpan timeout = default)
4851
{

0 commit comments

Comments
 (0)