Skip to content

Commit

Permalink
clean database before test instead of after so that one can inspect t…
Browse files Browse the repository at this point in the history
…he data after the test is done
  • Loading branch information
Barsonax committed Apr 5, 2024
1 parent 4dbad52 commit 5e4bccc
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected override IHost CreateHost(IHostBuilder builder)
// enough" for the address it is listening on to be available.
_host = builder.Build();
_host.Start();
_pooledDatabase.EnsureInitialized(_host);
_pooledDatabase.EnsureDatabaseIsReadyForTest(_host);

// Extract the selected dynamic port out of the Kestrel server
// and assign it onto the client options for convenience so it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override IHost CreateHost(IHostBuilder builder)
});

var app = base.CreateHost(builder);
_pooledDatabase.EnsureInitialized(app);
_pooledDatabase.EnsureDatabaseIsReadyForTest(app);

return app;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override IHost CreateHost(IHostBuilder builder)
});

var app = base.CreateHost(builder);
_pooledDatabase.EnsureInitialized(app);
_pooledDatabase.EnsureDatabaseIsReadyForTest(app);

return app;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override IHost CreateHost(IHostBuilder builder)
});

var app = base.CreateHost(builder);
_pooledDatabase.EnsureInitialized(app);
_pooledDatabase.EnsureDatabaseIsReadyForTest(app);

return app;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override IHost CreateHost(IHostBuilder builder)
});

var app = base.CreateHost(builder);
_pooledDatabase.EnsureInitialized(app);
_pooledDatabase.EnsureDatabaseIsReadyForTest(app);

return app;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override IHost CreateHost(IHostBuilder builder)
});

var app = base.CreateHost(builder);
_pooledDatabase.EnsureInitialized(app);
_pooledDatabase.EnsureDatabaseIsReadyForTest(app);

return app;
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Razor/Razor.Playwright/TestSetup/RazorSut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override IHost CreateHost(IHostBuilder builder)
// enough" for the address it is listening on to be available.
_host = builder.Build();
_host.Start();
_pooledDatabase.EnsureInitialized(_host);
_pooledDatabase.EnsureDatabaseIsReadyForTest(_host);

// Extract the selected dynamic port out of the Kestrel server
// and assign it onto the client options for convenience so it
Expand Down
2 changes: 1 addition & 1 deletion Examples/Vue/Vue.Playwright/TestSetup/VueSut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected override IHost CreateHost(IHostBuilder builder)
// enough" for the address it is listening on to be available.
_host = builder.Build();
_host.Start();
_pooledDatabase.EnsureInitialized(_host);
_pooledDatabase.EnsureDatabaseIsReadyForTest(_host);

// Extract the selected dynamic port out of the Kestrel server
// and assign it onto the client options for convenience so it
Expand Down
13 changes: 5 additions & 8 deletions TestExamplesDotnet.Mssql/MsSqlDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ public void Initialize(IHost host)
}
}

public async ValueTask Clean()
public async Task Clean()
{
if (_initialized)
{
await using var conn = new SqlConnection(ConnectionString);
await conn.OpenAsync();
await using var conn = new SqlConnection(ConnectionString);
await conn.OpenAsync();

_respawner ??= await Respawner.CreateAsync(conn, _respawnerOptions);
_respawner ??= await Respawner.CreateAsync(conn, _respawnerOptions);

await _respawner.ResetAsync(conn);
}
await _respawner.ResetAsync(conn);
}
}
13 changes: 5 additions & 8 deletions TestExamplesDotnet.PostgreSql/PostgreSqlDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ public void Initialize(IHost host)
}
}

public async ValueTask Clean()
public async Task Clean()
{
if (_initialized)
{
await using var conn = new NpgsqlConnection(ConnectionString);
await conn.OpenAsync();
await using var conn = new NpgsqlConnection(ConnectionString);
await conn.OpenAsync();

_respawner ??= await Respawner.CreateAsync(conn, _respawnerOptions);
_respawner ??= await Respawner.CreateAsync(conn, _respawnerOptions);

await _respawner.ResetAsync(conn);
}
await _respawner.ResetAsync(conn);
}
}
2 changes: 1 addition & 1 deletion TestExamplesDotnet/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public interface IDatabase
string ConnectionString { get; }

public void Initialize(IHost host);
public ValueTask Clean();
public Task Clean();
}
4 changes: 2 additions & 2 deletions TestExamplesDotnet/PooledDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ internal PooledDatabase(ObjectPool<IDatabase> pool)

public string ConnectionString => _database.ConnectionString;

public void EnsureInitialized(IHost host)
public void EnsureDatabaseIsReadyForTest(IHost host)
{
_database.Initialize(host);
_database.Clean().GetAwaiter().GetResult();
}

public async ValueTask DisposeAsync()

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / BuildSolution

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / BuildSolution

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiJwtAuthNunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiJwtAuthNunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiMsSqlNunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiMsSqlNunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / AngularAuthPlaywright / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / AngularAuthPlaywright / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiMsSqlXunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiMsSqlXunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiPostgreSqlNunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiPostgreSqlNunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiPostgreSqlXunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / ApiPostgreSqlXunit / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / MigrationsMsSqlEntityFrameworkCore / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / MigrationsMsSqlEntityFrameworkCore / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / RazorPlaywright / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / RazorPlaywright / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / VuePlaywright / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check failure on line 26 in TestExamplesDotnet/PooledDatabase.cs

View workflow job for this annotation

GitHub Actions / VuePlaywright / build_and_test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
await _database.Clean();
_pool.Return(_database);
}
}

0 comments on commit 5e4bccc

Please sign in to comment.