forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSynchronization.cpp
More file actions
63 lines (48 loc) · 1.81 KB
/
Copy pathSynchronization.cpp
File metadata and controls
63 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "TestCommon.h"
#include <AppInstallerSynchronization.h>
using namespace AppInstaller::Synchronization;
TEST_CASE("CPIL_BlocksOthers", "[CrossProcessInstallLock]")
{
wil::unique_event signal;
signal.create();
AppInstaller::ProgressCallback progress;
{
CrossProcessInstallLock mainThreadLock;
mainThreadLock.Acquire(progress);
std::thread otherThread([&signal, &progress]() {
CrossProcessInstallLock otherThreadLock;
otherThreadLock.Acquire(progress);
signal.SetEvent();
});
// In the event of bugs, we don't want to block the test waiting forever
otherThread.detach();
REQUIRE(!signal.wait(500));
}
// Upon release of the writer, the other thread should signal
REQUIRE(signal.wait(500));
}
TEST_CASE("CPIL_CancelEndsWait", "[CrossProcessInstallLock]")
{
wil::unique_event signal;
signal.create();
AppInstaller::ProgressCallback progress;
CrossProcessInstallLock mainThreadLock;
mainThreadLock.Acquire(progress);
std::optional<bool> otherThreadAcquireResult = std::nullopt;
std::thread otherThread([&]() {
CrossProcessInstallLock otherThreadLock;
otherThreadAcquireResult = otherThreadLock.Acquire(progress);
signal.SetEvent();
});
// In the event of bugs, we don't want to block the test waiting forever
otherThread.detach();
REQUIRE(!signal.wait(500));
progress.Cancel();
// Upon release of the writer, the other thread should signal
REQUIRE(signal.wait(500));
REQUIRE(otherThreadAcquireResult.has_value());
REQUIRE(!otherThreadAcquireResult.value());
}