@@ -327,3 +327,73 @@ def test_set_hostname(fake_base):
327327 bad_name = "bad_123-ABC%-"
328328 fake_base ._set_hostname (bad_name )
329329 assert fake_base ._hostname == "bad123-ABC"
330+
331+
332+ def test_snap_refresh (fake_process , fake_executor , fake_base ):
333+ """Disable and wait for snap refreshes."""
334+ fake_process .register_subprocess (
335+ [* DEFAULT_FAKE_CMD , "snap" , "refresh" , "--hold" ],
336+ returncode = 0 ,
337+ )
338+ fake_process .register_subprocess (
339+ [* DEFAULT_FAKE_CMD , "snap" , "watch" , "--last=auto-refresh?" ],
340+ returncode = 0 ,
341+ )
342+
343+ fake_base ._disable_and_wait_for_snap_refresh (executor = fake_executor )
344+
345+
346+ def test_snap_refresh_hold_error (fake_process , fake_executor , fake_base ):
347+ """Error on failure to hold refreshes."""
348+ fake_process .register_subprocess (
349+ [* DEFAULT_FAKE_CMD , "snap" , "refresh" , "--hold" ],
350+ stderr = "test error" ,
351+ returncode = 1 ,
352+ )
353+ fake_process .register_subprocess (
354+ [* DEFAULT_FAKE_CMD , "snap" , "watch" , "--last=auto-refresh?" ],
355+ returncode = 0 ,
356+ )
357+
358+ with pytest .raises (BaseConfigurationError ) as err :
359+ fake_base ._disable_and_wait_for_snap_refresh (executor = fake_executor )
360+
361+ assert err .value .brief == "Failed to hold snap refreshes."
362+ assert err .value .details
363+ assert "test error" in err .value .details
364+
365+
366+ def test_snap_refresh_watch_error (fake_process , fake_executor , fake_base ):
367+ """Error on failure of 'snap watch'."""
368+ stderr = "error: daemon is stopping to wait for socket activation"
369+ fake_base ._timeout_complex = 0.01
370+ fake_process .register_subprocess (
371+ [* DEFAULT_FAKE_CMD , "snap" , "refresh" , "--hold" ],
372+ returncode = 0 ,
373+ )
374+ fake_process .register_subprocess (
375+ [* DEFAULT_FAKE_CMD , "snap" , "watch" , "--last=auto-refresh?" ],
376+ stderr = stderr ,
377+ returncode = 1 ,
378+ )
379+
380+ with pytest .raises (BaseConfigurationError ) as err :
381+ fake_base ._disable_and_wait_for_snap_refresh (executor = fake_executor )
382+
383+ assert err .value .brief == "Failed to wait for snap refreshes to complete."
384+ assert err .value .details
385+ assert stderr in err .value .details
386+
387+
388+ def test_snap_refresh_watch_retry (fake_process , fake_executor , fake_base ):
389+ """Retry when 'snap watch' fails."""
390+ fake_process .register_subprocess (
391+ [* DEFAULT_FAKE_CMD , "snap" , "refresh" , "--hold" ],
392+ returncode = 0 ,
393+ )
394+ # fail twice then succeed
395+ snap_watch = [* DEFAULT_FAKE_CMD , "snap" , "watch" , "--last=auto-refresh?" ]
396+ for returncode in (1 , 1 , 0 ):
397+ fake_process .register_subprocess (snap_watch , returncode = returncode )
398+
399+ fake_base ._disable_and_wait_for_snap_refresh (executor = fake_executor )
0 commit comments