File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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;
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 115115 {
116116 mocks.erase (iter);
117117 HCHttpCallCloseHandle (call);
118+ httpSingleton->m_mockCycleIndex .clear ();
118119 return S_OK;
119120 }
120121 }
139140 }
140141
141142 httpSingleton->m_mocks .clear ();
143+ httpSingleton->m_mockCycleIndex .clear ();
142144 return S_OK;
143145}
144146CATCH_RETURN ()
You can’t perform that action at this time.
0 commit comments