Skip to content

Commit

Permalink
feat(tests): More tests for driver fallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
na2axl committed Nov 14, 2024
1 parent 8597c78 commit eca3893
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion tests/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ TEST_CASE("Engine Tests", "[engine][core][amplitude]")
REQUIRE(amEngine->Deinitialize());
Engine::RegisterDefaultPlugins();
}

THEN("it fallbacks to the null driver when initialized without a default driver")
{
REQUIRE(amEngine->Deinitialize());
REQUIRE(amEngine->Initialize(AM_OS_STRING("tests.invalid.unknown_driver.config.amconfig")));
REQUIRE(amEngine->GetDriver()->GetName() != "unknown");
REQUIRE(amEngine->GetDriver()->GetName() == "null");
REQUIRE(amEngine->Deinitialize());
}
}

GIVEN("an empty driver config")
Expand All @@ -91,7 +100,6 @@ TEST_CASE("Engine Tests", "[engine][core][amplitude]")

REQUIRE(amEngine->Deinitialize());
REQUIRE(amEngine->Initialize(AM_OS_STRING("tests.invalid.unset_driver.config.amconfig")));
REQUIRE(amEngine->GetDriver()->GetName() != "unknown");
REQUIRE(amEngine->GetDriver()->GetName() == "null");
REQUIRE(amEngine->Deinitialize());
}
Expand All @@ -104,6 +112,14 @@ TEST_CASE("Engine Tests", "[engine][core][amplitude]")
REQUIRE(amEngine->Deinitialize());
Engine::RegisterDefaultPlugins();
}

THEN("it fallbacks to the null driver when initialized without a default driver")
{
REQUIRE(amEngine->Deinitialize());
REQUIRE(amEngine->Initialize(AM_OS_STRING("tests.invalid.unset_driver.config.amconfig")));
REQUIRE(amEngine->GetDriver()->GetName() == "null");
REQUIRE(amEngine->Deinitialize());
}
}

GIVEN("a failing driver")
Expand All @@ -113,8 +129,19 @@ TEST_CASE("Engine Tests", "[engine][core][amplitude]")
THEN("it cannot be initialized with a failing driver")
{
REQUIRE(amEngine->Deinitialize());
Engine::UnregisterDefaultPlugins();
REQUIRE_FALSE(amEngine->Initialize(AM_OS_STRING("tests.invalid.failing_driver.config.amconfig")));
REQUIRE(amEngine->Deinitialize());
Engine::RegisterDefaultPlugins();
}

THEN("it fallbacks to the null driver when initialized with a failing driver")
{
REQUIRE(amEngine->Deinitialize());
REQUIRE(amEngine->Initialize(AM_OS_STRING("tests.invalid.failing_driver.config.amconfig")));
REQUIRE(amEngine->GetDriver()->GetName() != "failing");
REQUIRE(amEngine->GetDriver()->GetName() == "null");
REQUIRE(amEngine->Deinitialize());
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AwaitableDummyPoolTask final : public Thread::AwaitablePoolTask
public:
void AwaitableWork() override
{
Thread::Sleep(500);
Thread::Sleep(1000);
_isExecuted = true;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ TEST_CASE("Thread Pool Tests", "[thread][amplitude]")

THEN("the task is executed")
{
Thread::Sleep(1050); // Wait for the task to execute
Thread::Sleep(1100); // Wait for the task to execute
REQUIRE(task->IsExecuted());

AND_THEN("the task is removed from the pool")
Expand Down

0 comments on commit eca3893

Please sign in to comment.