Skip to content

Commit 51309d3

Browse files
committed
Spelling and test fixes
1 parent f3803c9 commit 51309d3

File tree

6 files changed

+119
-18
lines changed

6 files changed

+119
-18
lines changed

src/AppInstallerCLICore/ContextOrchestrator.cpp

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ namespace AppInstaller::CLI::Execution
214214
}
215215
}
216216

217-
bool ContextOrchestrator::WaitForRunningItems(DWORD timeoutMiliseconds)
217+
bool ContextOrchestrator::WaitForRunningItems(DWORD timeoutMilliseconds)
218218
{
219219
std::lock_guard<std::mutex> lock{ m_queueLock };
220220
for (const auto& queue : m_commandQueues)
221221
{
222-
if (!queue.second->WaitForEmptyQueue(timeoutMiliseconds))
222+
if (!queue.second->WaitForEmptyQueue(timeoutMilliseconds))
223223
{
224224
return false;
225225
}
@@ -228,6 +228,25 @@ namespace AppInstaller::CLI::Execution
228228
return true;
229229
}
230230

231+
std::string ContextOrchestrator::GetStatusString()
232+
{
233+
std::ostringstream stream;
234+
235+
std::lock_guard<std::mutex> lock{ m_queueLock };
236+
237+
if (!m_enabled)
238+
{
239+
stream << "Disabled due to " << ToIntegral(m_disabledReason) << std::endl;
240+
}
241+
242+
for (const auto& queue : m_commandQueues)
243+
{
244+
stream << queue.second->GetStatusString();
245+
}
246+
247+
return stream.str();
248+
}
249+
231250
_Requires_lock_held_(m_itemLock)
232251
std::deque<std::shared_ptr<OrchestratorQueueItem>>::iterator OrchestratorQueue::FindIteratorById(const OrchestratorQueueItemId& comparisonQueueItemId)
233252
{
@@ -420,9 +439,37 @@ namespace AppInstaller::CLI::Execution
420439
m_queueEmpty.wait();
421440
}
422441

423-
bool OrchestratorQueue::WaitForEmptyQueue(DWORD timeoutMiliseconds)
442+
bool OrchestratorQueue::WaitForEmptyQueue(DWORD timeoutMilliseconds)
443+
{
444+
return m_queueEmpty.wait(timeoutMilliseconds);
445+
}
446+
447+
std::string OrchestratorQueue::GetStatusString()
424448
{
425-
return m_queueEmpty.wait(timeoutMiliseconds);
449+
std::ostringstream stream;
450+
stream << m_commandName << '[' << m_allowedThreads << "]\n";
451+
452+
std::map<OrchestratorQueueItemState, size_t> stateCounts;
453+
stateCounts[OrchestratorQueueItemState::NotQueued] = 0;
454+
stateCounts[OrchestratorQueueItemState::Queued] = 0;
455+
stateCounts[OrchestratorQueueItemState::Running] = 0;
456+
stateCounts[OrchestratorQueueItemState::Cancelled] = 0;
457+
458+
{
459+
std::lock_guard<std::mutex> lock{ m_itemLock };
460+
461+
for (const auto& item : m_queueItems)
462+
{
463+
stateCounts[item->GetState()] += 1;
464+
}
465+
}
466+
467+
for (const auto& stateCount : stateCounts)
468+
{
469+
stream << " " << ToString(stateCount.first) << " : " << stateCount.second << std::endl;
470+
}
471+
472+
return stream.str();
426473
}
427474

428475
bool OrchestratorQueue::RemoveItemInState(const OrchestratorQueueItem& item, OrchestratorQueueItemState state, bool isGlobalRemove)
@@ -530,4 +577,16 @@ namespace AppInstaller::CLI::Execution
530577
item->AddCommand(std::make_unique<::AppInstaller::CLI::COMRepairCommand>(RootCommand::CommandName));
531578
return item;
532579
}
580+
581+
std::string_view ToString(OrchestratorQueueItemState state)
582+
{
583+
switch (state)
584+
{
585+
case OrchestratorQueueItemState::NotQueued: return "NotQueued";
586+
case OrchestratorQueueItemState::Queued: return "Queued";
587+
case OrchestratorQueueItemState::Running: return "Running";
588+
case OrchestratorQueueItemState::Cancelled: return "Cancelled";
589+
default: return "Unknown";
590+
}
591+
}
533592
}

src/AppInstallerCLICore/ContextOrchestrator.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Command.h"
1111
#include "COMContext.h"
1212
#include <wil/resource.h>
13+
#include <string>
1314
#include <string_view>
1415

1516
namespace AppInstaller::CLI::Execution
@@ -26,6 +27,8 @@ namespace AppInstaller::CLI::Execution
2627
Cancelled
2728
};
2829

30+
std::string_view ToString(OrchestratorQueueItemState state);
31+
2932
struct OrchestratorQueueItemId
3033
{
3134
OrchestratorQueueItemId(std::wstring packageId, std::wstring sourceId) : m_packageId(std::move(packageId)), m_sourceId(std::move(sourceId)) {}
@@ -137,7 +140,10 @@ namespace AppInstaller::CLI::Execution
137140
// Waits for running items to complete; waits up to full time out in *each* queue.
138141
// Returns true to indicate all queues are empty before the timeout.
139142
// Intended for test use.
140-
bool WaitForRunningItems(DWORD timeoutMiliseconds);
143+
bool WaitForRunningItems(DWORD timeoutMilliseconds);
144+
145+
// Gets a string that represents the current state of the orchestrator.
146+
std::string GetStatusString();
141147

142148
private:
143149
std::mutex m_queueLock;
@@ -189,7 +195,10 @@ namespace AppInstaller::CLI::Execution
189195
// Waits until the empty queue event is signaled.
190196
// Returns true to indicate the queue is empty before the timeout.
191197
// Intended for tests.
192-
bool WaitForEmptyQueue(DWORD timeoutMiliseconds);
198+
bool WaitForEmptyQueue(DWORD timeoutMilliseconds);
199+
200+
// Gets a string that represents the current state of the queue.
201+
std::string GetStatusString();
193202

194203
private:
195204
// Enqueues an item.

src/AppInstallerCLIE2ETests/Interop/Shutdown.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void NoActiveOperations()
4848
this.SendMessageAndLog(server, WindowMessage.EndSession);
4949
this.SendMessageAndLog(server, WindowMessage.Close);
5050

51-
Assert.IsTrue(server.Process.HasExited);
51+
Assert.IsTrue(server.Process.WaitForExit(5000));
5252
}
5353

5454
/// <summary>
@@ -84,7 +84,7 @@ public async Task ActiveInstallOperation()
8484
this.SendMessageAndLog(server, WindowMessage.EndSession);
8585
this.SendMessageAndLog(server, WindowMessage.Close);
8686

87-
Assert.IsTrue(server.Process.HasExited);
87+
Assert.IsTrue(server.Process.WaitForExit(5000));
8888

8989
var installResult = await installOperation;
9090

src/AppInstallerCLITests/ContextOrchestrator.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,31 +157,50 @@ TEST_CASE("ContextOrchestrator_CancelAllItems", "[context_orchestrator]")
157157

158158
auto downloadQueued = CreateTestItem("downloadQueued");
159159
auto downloadRunning = CreateTestItem("downloadRunning");
160-
wil::slim_event_manual_reset downloadRunningEvent;
161-
downloadRunning.Context->OperationCallback = [&]() { downloadRunningEvent.wait(); };
160+
wil::slim_event_manual_reset downloadBegunEvent;
161+
wil::slim_event_manual_reset downloadWaitingEvent;
162+
downloadRunning.Context->DownloadCallback = [&]()
163+
{
164+
downloadBegunEvent.SetEvent();
165+
downloadWaitingEvent.wait();
166+
};
162167

163168
auto operationQueued = CreateTestItem("operationQueued");
164169
auto operationRunning = CreateTestItem("operationRunning");
165-
wil::slim_event_manual_reset operationRunningEvent;
166-
operationRunning.Context->OperationCallback = [&]() { operationRunningEvent.wait(); };
170+
wil::slim_event_manual_reset operationBegunEvent;
171+
wil::slim_event_manual_reset operationWaitingEvent;
172+
operationRunning.Context->OperationCallback = [&]()
173+
{
174+
operationBegunEvent.SetEvent();
175+
operationWaitingEvent.wait();
176+
};
167177

168178
orchestrator.EnqueueAndRunItem(operationRunning.QueueItem);
169179
orchestrator.EnqueueAndRunItem(operationQueued.QueueItem);
170180
orchestrator.EnqueueAndRunItem(downloadRunning.QueueItem);
171181
orchestrator.EnqueueAndRunItem(downloadQueued.QueueItem);
172182

183+
operationBegunEvent.wait(c_DefaultWaitInMs);
184+
downloadBegunEvent.wait(c_DefaultWaitInMs);
185+
186+
INFO("Pre-shutdown state: \n" << orchestrator.GetStatusString());
187+
173188
auto reason = AppInstaller::CancelReason::AppShutdown;
174189
orchestrator.Disable(reason);
175190
orchestrator.CancelQueuedItems(reason);
176191

177-
operationRunningEvent.SetEvent();
178-
downloadRunningEvent.SetEvent();
192+
operationWaitingEvent.SetEvent();
193+
downloadWaitingEvent.SetEvent();
179194

180-
REQUIRE(orchestrator.WaitForRunningItems(c_DefaultWaitInMs));
195+
if (!orchestrator.WaitForRunningItems(c_DefaultWaitInMs))
196+
{
197+
INFO("Post-wait state: \n" << orchestrator.GetStatusString());
198+
FAIL("Timed out waiting for orchestrator to empty");
199+
}
181200

182201
auto checkQueueItem = [](TestQueueItem& item)
183202
{
184-
REQUIRE(item.QueueItem->GetCompletedEvent().wait(c_DefaultWaitInMs));
203+
REQUIRE(item.QueueItem->GetCompletedEvent().wait(0));
185204
REQUIRE(item.Context->IsTerminated());
186205
REQUIRE(E_ABORT == item.Context->GetTerminationHR());
187206
};

src/Microsoft.Management.Configuration.UnitTests/Fixtures/UnitTestFixture.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Microsoft.Management.Configuration.UnitTests.Fixtures
88
{
99
using System;
10+
using System.Diagnostics.CodeAnalysis;
1011
using System.IO;
1112
using System.Reflection;
1213
using Microsoft.Management.Configuration.Processor;
@@ -62,7 +63,7 @@ public UnitTestFixture(IMessageSink messageSink)
6263
throw new DirectoryNotFoundException(this.ExternalModulesPath);
6364
}
6465

65-
this.ConfigurationStatics = new ConfigurationStaticFunctions().As<IConfigurationStatics2>();
66+
this.RecreateStatics();
6667
}
6768

6869
/// <summary>
@@ -88,7 +89,16 @@ public UnitTestFixture(IMessageSink messageSink)
8889
/// <summary>
8990
/// Gets the configuration statics object to use.
9091
/// </summary>
91-
internal IConfigurationStatics2 ConfigurationStatics { get; private init; }
92+
internal IConfigurationStatics2 ConfigurationStatics { get; private set; }
93+
94+
/// <summary>
95+
/// Creates a new statics object for use by the tests.
96+
/// </summary>
97+
[MemberNotNull("ConfigurationStatics")]
98+
public void RecreateStatics()
99+
{
100+
this.ConfigurationStatics = new ConfigurationStaticFunctions().As<IConfigurationStatics2>();
101+
}
92102

93103
/// <summary>
94104
/// Creates a runspace adding the test module path.

src/Microsoft.Management.Configuration.UnitTests/Tests/ShutdownTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public ShutdownTests(UnitTestFixture fixture, ITestOutputHelper log)
3838
[Fact]
3939
public void ShutdownSynchronization_SyncCall()
4040
{
41+
this.Fixture.RecreateStatics();
42+
4143
ConfigurationSet configurationSet = this.ConfigurationSet();
4244
ConfigurationUnit configurationUnitWaits = this.ConfigurationUnit();
4345
ConfigurationUnit configurationUnitWorks = this.ConfigurationUnit();
@@ -112,6 +114,8 @@ public void ShutdownSynchronization_SyncCall()
112114
[Fact]
113115
public void ShutdownSynchronization_AsyncCall()
114116
{
117+
this.Fixture.RecreateStatics();
118+
115119
ConfigurationSet configurationSet = this.ConfigurationSet();
116120
ConfigurationUnit configurationUnitWaits = this.ConfigurationUnit();
117121
ConfigurationUnit configurationUnitWorks = this.ConfigurationUnit();

0 commit comments

Comments
 (0)