Skip to content

Commit

Permalink
added test to check if the tables is full after scenarion conpleted (#15
Browse files Browse the repository at this point in the history
)
  • Loading branch information
OlenaKostash authored Sep 16, 2024
1 parent 63bbab2 commit eacc421
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/Nbomber.Sinks.Timescale.Tests/Infra/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,21 @@ public async Task<int> GetDBSchemaVersion()
return -1;
}
}

public async Task<int> GetDataCount(string tableName)
{
using var connection = new NpgsqlConnection(_connectionString);

try
{
var result = await connection.ExecuteScalarAsync<int>($@"SELECT COUNT(*) FROM {tableName};");

return result;
}
catch (Exception ex)
{
return -1;
}
}
}
}
30 changes: 30 additions & 0 deletions tests/Nbomber.Sinks.Timescale.Tests/TimescaleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,35 @@ public async Task When_DataBase_Empty_Migrator_Should_Create_DB_WithSinkSchemaVe

Assert.Equal(DbMigrations.SinkSchemaVersion, dbSchemaVersion);
}


[Fact]
public async Task DataBase_IsFull_After_Scenario_Completed()
{
await fixture.TestHelper.DeleteTables();

var scenario = Scenario.Create("user_flow_scenario", async context =>
{
var step1 = await Step.Run("step1", context, async () =>
{
await Task.Delay(TimeSpan.FromSeconds(1));
return Response.Ok(sizeBytes: 10, statusCode: "200");
});
return Response.Ok(statusCode: "201", message: "hey");
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.KeepConstant(1, during: TimeSpan.FromSeconds(10)));

NBomberRunner
.RegisterScenarios(scenario)
.WithReportingSinks(fixture.CreateTimescaleDbSinkInstance())
.Run();

var sessionTableCount = await fixture.TestHelper.GetDataCount(SqlQueries.SessionsTable);
var stepStatsTableCount = await fixture.TestHelper.GetDataCount(SqlQueries.StepStatsTable);

Assert.True(sessionTableCount > 0);
Assert.True(stepStatsTableCount > 0);
}
}
}

0 comments on commit eacc421

Please sign in to comment.