Skip to content

Commit eeb3bfe

Browse files
authored
Merge branch 'main' into user/brianpe/fromwindows
2 parents 53cec19 + ab6a11b commit eeb3bfe

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

Source/Global/global.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ typedef struct http_singleton
7878
// Mock state
7979
std::recursive_mutex m_mocksLock;
8080
http_internal_vector<HC_MOCK_CALL*> m_mocks;
81+
http_internal_map<http_internal_string, size_t> m_mockCycleIndex;
8182

8283
std::recursive_mutex m_sharedPtrsLock;
8384
http_internal_unordered_map<void*, std::shared_ptr<void>> m_sharedPtrs;

Source/Mock/lhc_mock.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,37 @@ bool Mock_Internal_HCHttpCallPerformAsync(
6060
auto& mocks{ httpSingleton->m_mocks };
6161
HC_MOCK_CALL* mock{ nullptr };
6262

63-
// Use the most recently added mock that matches (similar to a stack).
64-
for (auto iter = mocks.rbegin(); iter != mocks.rend(); ++iter)
63+
// Collect all matching mocks in insertion order
64+
http_internal_vector<HC_MOCK_CALL*> matchingMocks;
65+
for (auto& m : mocks)
6566
{
66-
if (DoesMockCallMatch(*iter, originalCall))
67+
if (DoesMockCallMatch(m, originalCall))
6768
{
68-
mock = *iter;
69-
break;
69+
matchingMocks.push_back(m);
7070
}
7171
}
7272

73+
if (matchingMocks.empty())
74+
{
75+
return false;
76+
}
77+
78+
if (matchingMocks.size() == 1)
79+
{
80+
mock = matchingMocks[0];
81+
}
82+
else
83+
{
84+
// Build a key from method+url to track cycling position
85+
http_internal_string key{ originalCall->method };
86+
key += "|";
87+
key += originalCall->url;
88+
89+
auto& idx = httpSingleton->m_mockCycleIndex[key];
90+
mock = matchingMocks[idx % matchingMocks.size()];
91+
++idx;
92+
}
93+
7394
if (!mock)
7495
{
7596
return false;

Source/Mock/mock_publics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ try
115115
{
116116
mocks.erase(iter);
117117
HCHttpCallCloseHandle(call);
118+
httpSingleton->m_mockCycleIndex.clear();
118119
return S_OK;
119120
}
120121
}
@@ -139,6 +140,7 @@ try
139140
}
140141

141142
httpSingleton->m_mocks.clear();
143+
httpSingleton->m_mockCycleIndex.clear();
142144
return S_OK;
143145
}
144146
CATCH_RETURN()

0 commit comments

Comments
 (0)