Removed ununeeded includes from EBus EBus.h and Policies.h (#4256)
* Removed ununeeded includes from EBus EBus.h and Policies.h Updated the locations which needed those includes Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding missing include for <memory> to AWsClientAuthBus.h Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Remove the while true loop in the EBusQueuePolicy Execute() function The while true loop in Execute was for allowing additional functions to be queued in the middle of execution of current list of functions. That functionality was dangerous, because if a queued function added itself during execution unconditionally, then it would result in an infinite loop Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the AssetManager::DispatchEvents function to pump the AssetBus event queue until empty Queued Events on the AssetBus is able to queue additional events on that Bus during execution of those events. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Changed the AssetManager::DispatchEvents function to only execute the AssetBus queued events once Changed the AssetJobsFloodTest.AssetWithNoLoadReference_LoadDependencies_BehaviorObeyed test to dispatch events until the OnAssetContainerReady callback is signaled. This happens after every asset load to make sure that the expiring AssetContainer instances are removed from `AssetManager::m_ownedAssetContainer` container before retrying to load the same asset. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added a MaxTimeoutSeconds constant for the maximum amount of the time to run a single DispatchEvents loop Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
816a623c97
commit
090aa8f053
@@ -366,6 +366,42 @@ namespace UnitTest
|
||||
|
||||
};
|
||||
|
||||
static constexpr AZStd::chrono::seconds MaxDispatchTimeoutSeconds = BaseAssetManagerTest::DefaultTimeoutSeconds * 12;
|
||||
|
||||
template <typename Pred>
|
||||
bool DispatchEventsUntilCondition(AZ::Data::AssetManager& assetManager, Pred&& conditionPredicate,
|
||||
AZStd::chrono::seconds logIntervalSeconds = BaseAssetManagerTest::DefaultTimeoutSeconds,
|
||||
AZStd::chrono::seconds maxTimeoutSeconds = MaxDispatchTimeoutSeconds)
|
||||
{
|
||||
// If the Max Timeout is hit the test will be marked as a failure
|
||||
|
||||
AZStd::chrono::time_point dispatchEventTimeStart = AZStd::chrono::system_clock::now();
|
||||
AZStd::chrono::seconds dispatchEventNextLogTime = logIntervalSeconds;
|
||||
|
||||
while (!conditionPredicate())
|
||||
{
|
||||
AZStd::chrono::time_point currentTime = AZStd::chrono::system_clock::now();
|
||||
if (AZStd::chrono::seconds elapsedTime{ currentTime - dispatchEventTimeStart };
|
||||
elapsedTime >= dispatchEventNextLogTime)
|
||||
{
|
||||
const testing::TestInfo* test_info = ::testing::UnitTest::GetInstance()->current_test_info();
|
||||
AZ_Printf("AssetManagerLoadingTest", "The DispatchEventsUntiTimeout function has been waiting for %llu seconds"
|
||||
" in test %s.%s", elapsedTime.count(), test_info->test_case_name(), test_info->name());
|
||||
// Update the next log time to be the next multiple of DefaultTimeout Seconds
|
||||
// after current elapsed time
|
||||
dispatchEventNextLogTime = elapsedTime + logIntervalSeconds - ((elapsedTime + logIntervalSeconds) % logIntervalSeconds);
|
||||
if (elapsedTime >= maxTimeoutSeconds)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
assetManager.DispatchEvents();
|
||||
AZStd::this_thread::yield();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if AZ_TRAIT_DISABLE_FAILED_ASSET_MANAGER_TESTS || AZ_TRAIT_DISABLE_ASSET_MANAGER_FLOOD_TEST
|
||||
TEST_F(AssetJobsFloodTest, DISABLED_FloodTest)
|
||||
#else
|
||||
@@ -1358,42 +1394,74 @@ namespace UnitTest
|
||||
m_assetHandlerAndCatalog->m_numCreations = 0;
|
||||
m_assetHandlerAndCatalog->m_numDestructions = 0;
|
||||
{
|
||||
ContainerReadyListener containerLoadingCompleteListener(NoLoadAssetId);
|
||||
OnAssetReadyListener readyListener(NoLoadAssetId, azrtti_typeid<AssetWithAssetReference>());
|
||||
OnAssetReadyListener depenencyListener(MyAsset2Id, azrtti_typeid<AssetWithAssetReference>());
|
||||
OnAssetReadyListener dependencyListener(MyAsset2Id, azrtti_typeid<AssetWithAssetReference>());
|
||||
|
||||
SCOPED_TRACE("LoadDependencies_BehaviorObeyed");
|
||||
|
||||
auto AssetOnlyReady = [&readyListener]() -> bool
|
||||
{
|
||||
return readyListener.m_ready;
|
||||
};
|
||||
auto AssetAndDependencyReady = [&readyListener, &dependencyListener]() -> bool
|
||||
{
|
||||
return readyListener.m_ready && dependencyListener.m_ready;
|
||||
};
|
||||
auto AssetContainerReady = [&containerLoadingCompleteListener]() -> bool
|
||||
{
|
||||
return containerLoadingCompleteListener.m_ready;
|
||||
};
|
||||
|
||||
auto noLoadRef = m_testAssetManager->GetAsset(NoLoadAssetId, azrtti_typeid<AssetWithAssetReference>(),
|
||||
AZ::Data::AssetLoadBehavior::Default);
|
||||
|
||||
auto maxTimeout = AZStd::chrono::system_clock::now() + DefaultTimeoutSeconds;
|
||||
// Dispatch AssetBus events until the NoLoadAssetId has signaled an OnAssetReady
|
||||
// event or the timeout has been reached
|
||||
EXPECT_TRUE(DispatchEventsUntilCondition(*m_testAssetManager, AssetOnlyReady))
|
||||
<< "The DispatchEventsUntiTimeout function has not completed in "
|
||||
<< MaxDispatchTimeoutSeconds.count() << " seconds. The test will be marked as a failure\n";
|
||||
|
||||
// Dispatch AssetBus events until the asset container used to load
|
||||
// NoLoadAssetId has signaled an OnAssetContainerReady event
|
||||
// or the timeout has been reached
|
||||
// Wait until the current asset container has finished loading the NoLoadAssetId
|
||||
// before trigger another load
|
||||
// If the wait does not occur here, most likely what would occur is
|
||||
// the AssetManager::m_ownedAssetContainers object is still loading the NoLoadAssetId
|
||||
// using the default AssetLoadParameters
|
||||
// If a call to GetAsset occurs at this point while the Asset is still loading
|
||||
// it will ignore the new loadParams below and instead just re-use the existing
|
||||
// AssetContainerReader instance, resulting in the dependent MyAsset2Id not
|
||||
// being loaded
|
||||
// The function that can return an existing AssetContainer instance is the
|
||||
// AssetManager::GetAssetContainer. Since it can be in the middle of a load,
|
||||
// updating the AssetLoadParams would have an effect on the current in progress
|
||||
// load
|
||||
EXPECT_TRUE(DispatchEventsUntilCondition(*m_testAssetManager, AssetContainerReady))
|
||||
<< "The DispatchEventsUntiTimeout function has not completed in "
|
||||
<< MaxDispatchTimeoutSeconds.count() << " seconds. The test will be marked as a failure\n";
|
||||
|
||||
// Reset the ContainerLoadingComplete ready status back to 0
|
||||
containerLoadingCompleteListener.m_ready = 0;
|
||||
|
||||
while (!readyListener.m_ready)
|
||||
{
|
||||
m_testAssetManager->DispatchEvents();
|
||||
if (AZStd::chrono::system_clock::now() > maxTimeout)
|
||||
{
|
||||
break;
|
||||
}
|
||||
AZStd::this_thread::yield();
|
||||
}
|
||||
EXPECT_EQ(readyListener.m_ready, 1);
|
||||
EXPECT_EQ(depenencyListener.m_ready, 0);
|
||||
|
||||
AZ::Data::AssetLoadParameters loadParams(nullptr, AZ::Data::AssetDependencyLoadRules::LoadAll);
|
||||
loadParams.m_reloadMissingDependencies = true;
|
||||
auto loadDependencyRef = m_testAssetManager->GetAsset(NoLoadAssetId, azrtti_typeid<AssetWithAssetReference>(),
|
||||
AZ::Data::AssetLoadBehavior::Default, loadParams);
|
||||
|
||||
while (!depenencyListener.m_ready || !readyListener.m_ready)
|
||||
{
|
||||
m_testAssetManager->DispatchEvents();
|
||||
if (AZStd::chrono::system_clock::now() > maxTimeout)
|
||||
{
|
||||
break;
|
||||
}
|
||||
AZStd::this_thread::yield();
|
||||
}
|
||||
// Dispatch AssetBus events until the NoLoadAssetId and the MyAsset2Id has signaled
|
||||
// an OnAssetReady event or the timeout has been reached
|
||||
EXPECT_TRUE(DispatchEventsUntilCondition(*m_testAssetManager, AssetAndDependencyReady))
|
||||
<< "The DispatchEventsUntiTimeout function has not completed in "
|
||||
<< MaxDispatchTimeoutSeconds.count() << " seconds. The test will be marked as a failure\n";
|
||||
|
||||
EXPECT_EQ(readyListener.m_ready, 1);
|
||||
EXPECT_EQ(depenencyListener.m_ready, 1);
|
||||
EXPECT_EQ(dependencyListener.m_ready, 1);
|
||||
|
||||
EXPECT_TRUE(DispatchEventsUntilCondition(*m_testAssetManager, AssetContainerReady))
|
||||
<< "The DispatchEventsUntiTimeout function has not completed in "
|
||||
<< MaxDispatchTimeoutSeconds.count() << " seconds. The test will be marked as a failure\n";
|
||||
}
|
||||
|
||||
CheckFinishedCreationsAndDestructions();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
#include <AzCore/Math/Uuid.h>
|
||||
#include <AzCore/std/containers/unordered_set.h>
|
||||
|
||||
using namespace AZ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user