Skip to content

Commit 2e8238d

Browse files
committed
refactor(consume): rename/update w/enginex & pre-alloc group terminology
1 parent 88fc184 commit 2e8238d

File tree

4 files changed

+131
-123
lines changed

4 files changed

+131
-123
lines changed

src/pytest_plugins/consume/simulators/enginex/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Pytest fixtures for the `consume engine-reorg` simulator.
2+
Pytest fixtures for the `consume enginex` simulator.
33
44
Configures the hive back-end & EL clients for test execution with BlockchainEngineXFixtures.
55
"""
@@ -28,15 +28,15 @@ def pytest_configure(config):
2828
@pytest.fixture(scope="module")
2929
def test_suite_name() -> str:
3030
"""The name of the hive test suite used in this simulator."""
31-
return "eest/consume-engine-reorg"
31+
return "eest/consume-enginex"
3232

3333

3434
@pytest.fixture(scope="module")
3535
def test_suite_description() -> str:
3636
"""The description of the hive test suite used in this simulator."""
3737
return (
38-
"Execute blockchain tests against clients using the Engine API and shared clients "
39-
"using engine reorg fixtures."
38+
"Execute blockchain tests against clients using the Engine API with "
39+
"pre-allocation group optimization using Engine X fixtures."
4040
)
4141

4242

src/pytest_plugins/consume/simulators/helpers/client_wrapper.py

Lines changed: 78 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -191,85 +191,86 @@ def _get_genesis_header(self) -> dict:
191191
return to_json(self.fixture.genesis)
192192

193193

194-
class ReorgClient(ClientWrapper):
194+
class MultiTestClient(ClientWrapper):
195195
"""
196-
Client wrapper for the reorg simulator where clients are shared across tests.
196+
Client wrapper for multi-test execution where clients are used across tests.
197197
198198
This class manages clients that are reused across multiple tests in the same
199-
pre-allocation group, using blockchain reorganization to reset state between tests.
199+
pre-allocation group.
200200
"""
201201

202202
def __init__(
203203
self,
204204
pre_hash: str,
205205
client_type: ClientType,
206-
shared_pre_state: PreAllocGroup,
206+
pre_alloc_group: PreAllocGroup,
207207
):
208208
"""
209-
Initialize a reorg client wrapper.
209+
Initialize a multi-test client wrapper.
210210
211211
Args:
212212
pre_hash: The hash identifying the pre-allocation group
213213
client_type: The type of client to manage
214-
shared_pre_state: The shared pre-state data for this group
214+
pre_alloc_group: The pre-allocation group data for this group
215215
216216
"""
217217
super().__init__(client_type)
218218
self.pre_hash = pre_hash
219-
self.shared_pre_state = shared_pre_state
219+
self.pre_alloc_group = pre_alloc_group
220220

221221
def _get_fork(self) -> Fork:
222-
"""Get the fork from the shared pre-state."""
223-
return self.shared_pre_state.fork
222+
"""Get the fork from the pre-allocation group."""
223+
return self.pre_alloc_group.fork
224224

225225
def _get_chain_id(self) -> int:
226-
"""Get the chain ID from the shared pre-state environment."""
226+
"""Get the chain ID from the pre-allocation group environment."""
227227
# TODO: Environment doesn't have chain_id field - see work_in_progress.md
228228
return 1
229229

230230
def _get_pre_alloc(self) -> dict:
231-
"""Get the pre-allocation from the shared pre-state."""
232-
return to_json(self.shared_pre_state.pre)
231+
"""Get the pre-allocation from the pre-allocation group."""
232+
return to_json(self.pre_alloc_group.pre)
233233

234234
def _get_genesis_header(self) -> dict:
235-
"""Get the genesis header from the shared pre-state."""
236-
return self.shared_pre_state.genesis().model_dump(by_alias=True)
235+
"""Get the genesis header from the pre-allocation group."""
236+
return self.pre_alloc_group.genesis().model_dump(by_alias=True)
237237

238238
def set_client(self, client: Client) -> None:
239239
"""Override to log with pre_hash information."""
240240
if self._is_started:
241-
raise RuntimeError(f"Client for preHash {self.pre_hash} is already set")
241+
raise RuntimeError(f"Client for pre-allocation group {self.pre_hash} is already set")
242242

243243
self.client = client
244244
self._is_started = True
245245
logger.info(
246-
f"Reorg client ({self.client_type.name}) registered for preHash {self.pre_hash}"
246+
f"Multi-test client ({self.client_type.name}) registered for pre-allocation group "
247+
f"{self.pre_hash}"
247248
)
248249

249250
def stop(self) -> None:
250251
"""Override to log with pre_hash information."""
251252
if self._is_started:
252253
logger.info(
253-
f"Marking reorg client ({self.client_type.name}) for preHash {self.pre_hash} "
254-
f"as stopped after {self.test_count} tests"
254+
f"Marking multi-test client ({self.client_type.name}) for pre-allocation group "
255+
f"{self.pre_hash} as stopped after {self.test_count} tests"
255256
)
256257
self.client = None
257258
self._is_started = False
258259

259260

260-
class ReorgClientManager:
261+
class MultiTestClientManager:
261262
"""
262-
Singleton manager for coordinating reorg clients across test execution.
263+
Singleton manager for coordinating multi-test clients across test execution.
263264
264-
This class tracks all reorg clients by their preHash and ensures proper
265+
This class tracks all multi-test clients by their preHash and ensures proper
265266
lifecycle management including cleanup at session end.
266267
"""
267268

268-
_instance: Optional["ReorgClientManager"] = None
269+
_instance: Optional["MultiTestClientManager"] = None
269270
_initialized: bool
270271

271-
def __new__(cls) -> "ReorgClientManager":
272-
"""Ensure only one instance of ReorgClientManager exists."""
272+
def __new__(cls) -> "MultiTestClientManager":
273+
"""Ensure only one instance of MultiTestClientManager exists."""
273274
if cls._instance is None:
274275
cls._instance = super().__new__(cls)
275276
cls._instance._initialized = False
@@ -280,10 +281,10 @@ def __init__(self) -> None:
280281
if hasattr(self, "_initialized") and self._initialized:
281282
return
282283

283-
self.reorg_clients: Dict[str, ReorgClient] = {}
284+
self.multi_test_clients: Dict[str, MultiTestClient] = {}
284285
self.pre_alloc_path: Optional[Path] = None
285286
self._initialized = True
286-
logger.info("ReorgClientManager initialized")
287+
logger.info("MultiTestClientManager initialized")
287288

288289
def set_pre_alloc_path(self, path: Path) -> None:
289290
"""
@@ -296,9 +297,9 @@ def set_pre_alloc_path(self, path: Path) -> None:
296297
self.pre_alloc_path = path
297298
logger.debug(f"Pre-alloc path set to: {path}")
298299

299-
def load_shared_pre_state(self, pre_hash: str) -> PreAllocGroup:
300+
def load_pre_alloc_group(self, pre_hash: str) -> PreAllocGroup:
300301
"""
301-
Load the shared pre-state for a given preHash.
302+
Load the pre-allocation group for a given preHash.
302303
303304
Args:
304305
pre_hash: The hash identifying the pre-allocation group
@@ -312,63 +313,65 @@ def load_shared_pre_state(self, pre_hash: str) -> PreAllocGroup:
312313
313314
"""
314315
if self.pre_alloc_path is None:
315-
raise RuntimeError("Pre-alloc path not set in ReorgClientManager")
316+
raise RuntimeError("Pre-alloc path not set in MultiTestClientManager")
316317

317318
pre_alloc_file = self.pre_alloc_path / f"{pre_hash}.json"
318319
if not pre_alloc_file.exists():
319320
raise FileNotFoundError(f"Pre-allocation file not found: {pre_alloc_file}")
320321

321322
return PreAllocGroup.model_validate_json(pre_alloc_file.read_text())
322323

323-
def get_or_create_reorg_client(
324+
def get_or_create_multi_test_client(
324325
self,
325326
pre_hash: str,
326327
client_type: ClientType,
327-
) -> ReorgClient:
328+
) -> MultiTestClient:
328329
"""
329-
Get an existing ReorgClient or create a new one for the given preHash.
330+
Get an existing MultiTestClient or create a new one for the given preHash.
330331
331332
This method doesn't start the actual client - that's done by HiveTestSuite.
332-
It just manages the ReorgClient wrapper objects.
333+
It just manages the MultiTestClient wrapper objects.
333334
334335
Args:
335336
pre_hash: The hash identifying the pre-allocation group
336337
client_type: The type of client that will be started
337338
338339
Returns:
339-
The ReorgClient wrapper instance
340+
The MultiTestClient wrapper instance
340341
341342
"""
342-
# Check if we already have a ReorgClient for this preHash
343-
if pre_hash in self.reorg_clients:
344-
reorg_client = self.reorg_clients[pre_hash]
345-
if reorg_client.is_running:
346-
logger.debug(f"Found existing ReorgClient for preHash {pre_hash}")
347-
return reorg_client
343+
# Check if we already have a MultiTestClient for this preHash
344+
if pre_hash in self.multi_test_clients:
345+
multi_test_client = self.multi_test_clients[pre_hash]
346+
if multi_test_client.is_running:
347+
logger.debug(f"Found existing MultiTestClient for pre-allocation group {pre_hash}")
348+
return multi_test_client
348349
else:
349-
# ReorgClient exists but isn't running, remove it
350-
logger.warning(f"Found stopped ReorgClient for preHash {pre_hash}, removing")
351-
del self.reorg_clients[pre_hash]
350+
# MultiTestClient exists but isn't running, remove it
351+
logger.warning(
352+
f"Found stopped MultiTestClient for pre-allocation group {pre_hash}, removing"
353+
)
354+
del self.multi_test_clients[pre_hash]
352355

353-
# Load the shared pre-state for this group
354-
shared_pre_state = self.load_shared_pre_state(pre_hash)
356+
# Load the pre-allocation group for this group
357+
pre_alloc_group = self.load_pre_alloc_group(pre_hash)
355358

356-
# Create new ReorgClient wrapper
357-
reorg_client = ReorgClient(
359+
# Create new MultiTestClient wrapper
360+
multi_test_client = MultiTestClient(
358361
pre_hash=pre_hash,
359362
client_type=client_type,
360-
shared_pre_state=shared_pre_state,
363+
pre_alloc_group=pre_alloc_group,
361364
)
362365

363-
# Track the ReorgClient
364-
self.reorg_clients[pre_hash] = reorg_client
366+
# Track the MultiTestClient
367+
self.multi_test_clients[pre_hash] = multi_test_client
365368

366369
logger.info(
367-
f"Created new ReorgClient wrapper for preHash {pre_hash} "
368-
f"(total tracked clients: {len(self.reorg_clients)})"
370+
f"Created new MultiTestClient wrapper for pre-allocation group {pre_hash} "
371+
f"(total tracked clients: {len(self.multi_test_clients)})"
369372
)
370373

371-
return reorg_client
374+
return multi_test_client
372375

373376
def get_client_for_test(self, pre_hash: str) -> Optional[Client]:
374377
"""
@@ -381,38 +384,42 @@ def get_client_for_test(self, pre_hash: str) -> Optional[Client]:
381384
The client instance if available, None otherwise
382385
383386
"""
384-
if pre_hash in self.reorg_clients:
385-
reorg_client = self.reorg_clients[pre_hash]
386-
if reorg_client.is_running:
387-
reorg_client.increment_test_count()
388-
return reorg_client.client
387+
if pre_hash in self.multi_test_clients:
388+
multi_test_client = self.multi_test_clients[pre_hash]
389+
if multi_test_client.is_running:
390+
multi_test_client.increment_test_count()
391+
return multi_test_client.client
389392
return None
390393

391394
def stop_all_clients(self) -> None:
392-
"""Mark all reorg clients as stopped."""
393-
logger.info(f"Marking all {len(self.reorg_clients)} reorg clients as stopped")
395+
"""Mark all multi-test clients as stopped."""
396+
logger.info(f"Marking all {len(self.multi_test_clients)} multi-test clients as stopped")
394397

395-
for pre_hash, reorg_client in list(self.reorg_clients.items()):
398+
for pre_hash, multi_test_client in list(self.multi_test_clients.items()):
396399
try:
397-
reorg_client.stop()
400+
multi_test_client.stop()
398401
except Exception as e:
399-
logger.error(f"Error stopping ReorgClient for preHash {pre_hash}: {e}")
402+
logger.error(
403+
f"Error stopping MultiTestClient for pre-allocation group {pre_hash}: {e}"
404+
)
400405
finally:
401-
del self.reorg_clients[pre_hash]
406+
del self.multi_test_clients[pre_hash]
402407

403-
logger.info("All ReorgClient wrappers cleared")
408+
logger.info("All MultiTestClient wrappers cleared")
404409

405410
def get_client_count(self) -> int:
406-
"""Get the number of tracked reorg clients."""
407-
return len(self.reorg_clients)
411+
"""Get the number of tracked multi-test clients."""
412+
return len(self.multi_test_clients)
408413

409414
def get_test_counts(self) -> Dict[str, int]:
410-
"""Get test counts for each reorg client."""
411-
return {pre_hash: client.test_count for pre_hash, client in self.reorg_clients.items()}
415+
"""Get test counts for each multi-test client."""
416+
return {
417+
pre_hash: client.test_count for pre_hash, client in self.multi_test_clients.items()
418+
}
412419

413420
def reset(self) -> None:
414421
"""Reset the manager, clearing all state."""
415422
self.stop_all_clients()
416-
self.reorg_clients.clear()
423+
self.multi_test_clients.clear()
417424
self.pre_alloc_path = None
418-
logger.info("ReorgClientManager reset")
425+
logger.info("MultiTestClientManager reset")

0 commit comments

Comments
 (0)