Skip to content

Commit 473388e

Browse files
committed
fix(v3): defer setting pact broker source
When setting that Pact broker source, the verifier name _must_ be set; however, the FFI call to set this is deferred until the `verify()` call. The setting of the Pact broker source (which itself depends on knowing the verifier name) must therefore be also deferred. Signed-off-by: JP-Ellis <[email protected]>
1 parent 954c108 commit 473388e

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

Diff for: src/pact/v3/verifier.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
from contextlib import nullcontext
8181
from datetime import date
8282
from pathlib import Path
83-
from typing import TYPE_CHECKING, Any, Literal, TypedDict, overload
83+
from typing import TYPE_CHECKING, Any, Callable, Literal, TypedDict, overload
8484

8585
from typing_extensions import Self
8686
from yarl import URL
@@ -183,6 +183,11 @@ def __init__(self, name: str, host: str | None = None) -> None:
183183
self._state_handler: StateCallback | nullcontext[None] = nullcontext()
184184
self._disable_ssl_verification = False
185185
self._request_timeout = 5000
186+
# Using a broker source requires knowing the provider name, which is
187+
# only provided to the FFI just before verification. As such, we store
188+
# the broker source as a hook to be called just before verification, and
189+
# after the provider name is set.
190+
self._broker_source_hook: Callable[[], None] | None = None
186191

187192
def __str__(self) -> str:
188193
"""
@@ -1193,13 +1198,15 @@ def broker_source(
11931198
password,
11941199
token,
11951200
)
1196-
pact.v3.ffi.verifier_broker_source(
1201+
1202+
self._broker_source_hook = lambda: pact.v3.ffi.verifier_broker_source(
11971203
self._handle,
11981204
str(url.with_user(None).with_password(None)),
11991205
username,
12001206
password,
12011207
token,
12021208
)
1209+
12031210
return self
12041211

12051212
def verify(self) -> Self:
@@ -1233,6 +1240,9 @@ def verify(self) -> Self:
12331240
transport["scheme"],
12341241
)
12351242

1243+
if self._broker_source_hook:
1244+
self._broker_source_hook()
1245+
12361246
with self._message_producer, self._state_handler:
12371247
pact.v3.ffi.verifier_execute(self._handle)
12381248
logger.debug("Verifier executed")
@@ -1381,18 +1391,20 @@ def build(self) -> Verifier:
13811391
Returns:
13821392
The Verifier instance with the broker source added.
13831393
"""
1384-
pact.v3.ffi.verifier_broker_source_with_selectors(
1385-
self._verifier._handle, # noqa: SLF001
1386-
self._url,
1387-
self._username,
1388-
self._password,
1389-
self._token,
1390-
self._include_pending,
1391-
self._include_wip_since,
1392-
self._provider_tags or [],
1393-
self._provider_branch,
1394-
self._consumer_versions or [],
1395-
self._consumer_tags or [],
1394+
self._verifier._broker_source_hook = ( # noqa: SLF001
1395+
lambda: pact.v3.ffi.verifier_broker_source_with_selectors(
1396+
self._verifier._handle, # noqa: SLF001
1397+
self._url,
1398+
self._username,
1399+
self._password,
1400+
self._token,
1401+
self._include_pending,
1402+
self._include_wip_since,
1403+
self._provider_tags or [],
1404+
self._provider_branch,
1405+
self._consumer_versions or [],
1406+
self._consumer_tags or [],
1407+
)
13961408
)
13971409
self._built = True
13981410
return self._verifier

0 commit comments

Comments
 (0)