Skip to content

Commit e5cf633

Browse files
precommit
Signed-off-by: Jaya Venkatesh <jjayabaskar@nvidia.com>
1 parent 0ce0ffd commit e5cf633

File tree

4 files changed

+120
-116
lines changed

4 files changed

+120
-116
lines changed

distributed/client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5464,8 +5464,8 @@ def has_plugin(
54645464
Parameters
54655465
----------
54665466
plugin : str | plugin object | Sequence
5467-
Plugin to check. You can use the plugin object directly or the plugin name.
5468-
For plugin objects, they must have a 'name' attribute. You can also pass
5467+
Plugin to check. You can use the plugin object directly or the plugin name.
5468+
For plugin objects, they must have a 'name' attribute. You can also pass
54695469
a sequence of plugin objects or names.
54705470
54715471
Returns
@@ -5493,7 +5493,7 @@ async def _has_plugin_async(
54935493
self, plugin: str | WorkerPlugin | SchedulerPlugin | NannyPlugin | Sequence
54945494
) -> bool | dict[str, bool]:
54955495
"""Async implementation for checking plugin registration"""
5496-
5496+
54975497
# Convert plugin to list of names
54985498
if isinstance(plugin, str):
54995499
names_to_check = [plugin]
@@ -5524,10 +5524,12 @@ async def _has_plugin_async(
55245524
raise TypeError(
55255525
f"plugin must be a plugin object, name string, or Sequence. Got {type(plugin)}"
55265526
)
5527-
5527+
55285528
# Get status from scheduler
5529-
result = await self.scheduler.get_plugin_registration_status(names=names_to_check)
5530-
5529+
result = await self.scheduler.get_plugin_registration_status(
5530+
names=names_to_check
5531+
)
5532+
55315533
# Return single bool or dict based on input
55325534
if return_single:
55335535
return result[names_to_check[0]]

distributed/diagnostics/tests/test_nanny_plugin.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -218,29 +218,30 @@ async def test_nanny_plugin_with_broken_teardown_logs_on_close(c, s):
218218
assert "TestPlugin1 failed to teardown" in logs
219219
assert "test error" in logs
220220

221+
221222
@gen_cluster(client=True, nthreads=[("", 1)], Worker=Nanny)
222223
async def test_has_nanny_plugin_by_name(c, s, a):
223224
"""Test checking if nanny plugin is registered using string name"""
224-
225+
225226
class DuckPlugin(NannyPlugin):
226227
name = "duck-plugin"
227-
228+
228229
def setup(self, nanny):
229230
nanny.foo = 123
230-
231+
231232
def teardown(self, nanny):
232233
pass
233-
234+
234235
# Check non-existent plugin
235236
assert not await c.has_plugin("duck-plugin")
236-
237+
237238
# Register plugin
238239
await c.register_plugin(DuckPlugin())
239240
assert a.foo == 123
240-
241+
241242
# Check using string name
242243
assert await c.has_plugin("duck-plugin")
243-
244+
244245
# Unregister and check again
245246
await c.unregister_worker_plugin("duck-plugin", nanny=True)
246247
assert not await c.has_plugin("duck-plugin")
@@ -249,26 +250,26 @@ def teardown(self, nanny):
249250
@gen_cluster(client=True, nthreads=[("", 1)], Worker=Nanny)
250251
async def test_has_nanny_plugin_by_object(c, s, a):
251252
"""Test checking if nanny plugin is registered using plugin object"""
252-
253+
253254
class DuckPlugin(NannyPlugin):
254255
name = "duck-plugin"
255-
256+
256257
def setup(self, nanny):
257258
nanny.bar = 456
258-
259+
259260
def teardown(self, nanny):
260261
pass
261-
262+
262263
plugin = DuckPlugin()
263-
264+
264265
# Check before registration
265266
assert not await c.has_plugin(plugin)
266-
267+
267268
# Register and check
268269
await c.register_plugin(plugin)
269270
assert a.bar == 456
270271
assert await c.has_plugin(plugin)
271-
272+
272273
# Unregister and check
273274
await c.unregister_worker_plugin("duck-plugin", nanny=True)
274275
assert not await c.has_plugin(plugin)
@@ -277,89 +278,92 @@ def teardown(self, nanny):
277278
@gen_cluster(client=True, nthreads=[("", 1), ("", 1)], Worker=Nanny)
278279
async def test_has_nanny_plugin_multiple_nannies(c, s, a, b):
279280
"""Test checking nanny plugin with multiple nannies"""
280-
281+
281282
class DuckPlugin(NannyPlugin):
282283
name = "duck-plugin"
283-
284+
284285
def setup(self, nanny):
285286
nanny.multi = "setup"
286-
287+
287288
def teardown(self, nanny):
288289
pass
289-
290+
290291
# Check before registration
291292
assert not await c.has_plugin("duck-plugin")
292-
293+
293294
# Register plugin (should propagate to all nannies)
294295
await c.register_plugin(DuckPlugin())
295-
296+
296297
# Verify both nannies have the plugin
297298
assert a.multi == "setup"
298299
assert b.multi == "setup"
299-
300+
300301
# Check plugin is registered
301302
assert await c.has_plugin("duck-plugin")
302303

304+
303305
@gen_cluster(client=True, nthreads=[("", 1)], Worker=Nanny)
304306
async def test_has_nanny_plugin_custom_name_override(c, s, a):
305307
"""Test nanny plugin registered with custom name different from class name"""
306-
308+
307309
class DuckPlugin(NannyPlugin):
308310
name = "duck-plugin"
309-
311+
310312
def setup(self, nanny):
311313
nanny.custom = "test"
312-
314+
313315
def teardown(self, nanny):
314316
pass
315-
317+
316318
plugin = DuckPlugin()
317-
319+
318320
# Register with custom name (overriding the class name attribute)
319321
await c.register_plugin(plugin, name="custom-override")
320-
322+
321323
# Check with custom name works
322324
assert await c.has_plugin("custom-override")
323-
325+
324326
# Original name won't work since we overrode it
325327
assert not await c.has_plugin("duck-plugin")
326328

327329

328330
@gen_cluster(client=True, nthreads=[("", 1)], Worker=Nanny)
329331
async def test_has_nanny_plugin_list_check(c, s, a):
330332
"""Test checking multiple nanny plugins at once"""
331-
333+
332334
class IdempotentPlugin(NannyPlugin):
333335
name = "idempotentplugin"
334-
336+
335337
def setup(self, nanny):
336338
pass
337-
339+
338340
def teardown(self, nanny):
339341
pass
340-
342+
341343
class NonIdempotentPlugin(NannyPlugin):
342344
name = "nonidempotentplugin"
343-
345+
344346
def setup(self, nanny):
345347
pass
346-
348+
347349
def teardown(self, nanny):
348350
pass
349-
351+
350352
# Check multiple before registration
351-
result = await c.has_plugin(["idempotentplugin", "nonidempotentplugin", "nonexistent"])
353+
result = await c.has_plugin(
354+
["idempotentplugin", "nonidempotentplugin", "nonexistent"]
355+
)
352356
assert result == {
353357
"idempotentplugin": False,
354358
"nonidempotentplugin": False,
355359
"nonexistent": False,
356360
}
357-
361+
358362
# Register first plugin
359363
await c.register_plugin(IdempotentPlugin())
360364
result = await c.has_plugin(["idempotentplugin", "nonidempotentplugin"])
361365
assert result == {"idempotentplugin": True, "nonidempotentplugin": False}
362-
366+
363367
# Register second plugin
364368
await c.register_plugin(NonIdempotentPlugin())
365369
result = await c.has_plugin(["idempotentplugin", "nonidempotentplugin"])

0 commit comments

Comments
 (0)