def test_Job_cleanup_does_not_raise_on_error(tmpdir): """Test Job.cleanup().""" lease_path = _make_lease(tmpdir, 123) tmpdir.join('123.sock').write('') sock_path = str(tmpdir.join('123.sock')) for job in leasing.leases_iter(str(tmpdir)): os.unlink(lease_path) os.unlink(sock_path) job.cleanup()
def _clean_up_expired_leases(jobdir): """Clean up files for expired leases. We only care about active leases, so we can remove the stale files for expired leases. """ for lease in leasing.leases_iter(jobdir): if lease.expired(): lease.cleanup()
def test_Job_cleanup(tmpdir): """Test Job.cleanup().""" lease_path = _make_lease(tmpdir, 123) tmpdir.join('123.sock').write('') sock_path = str(tmpdir.join('123.sock')) for job in leasing.leases_iter(str(tmpdir)): logger.debug('Cleaning up %r', job) job.cleanup() assert not os.path.exists(lease_path) assert not os.path.exists(sock_path)
def test_Job_abort(tmpdir): """Test Job.abort().""" _make_lease(tmpdir, 123) with _abort_socket(tmpdir, 123) as proc: expired = list(leasing.leases_iter(str(tmpdir))) assert len(expired) > 0 for job in expired: job.abort() proc.wait() assert proc.returncode == 0
def _main_loop_body(metrics, jobdir): active_leases = { lease.id: lease for lease in leasing.leases_iter(jobdir) if not lease.expired() } _mark_expired_jobs_failed(metrics, active_leases) _abort_timed_out_jobs(active_leases) _abort_jobs_marked_aborting(active_leases) _abort_special_tasks_marked_aborted() _clean_up_expired_leases(jobdir)
def test_Job_abort_with_closed_socket(tmpdir): """Test Job.abort() with closed socket.""" _make_lease(tmpdir, 123) with _abort_socket(tmpdir, 123) as proc: proc.terminate() proc.wait() expired = list(leasing.leases_iter(str(tmpdir))) assert len(expired) > 0 for job in expired: with pytest.raises(socket.error): job.abort()
def test_Lease_abort_with_blocked_socket(tmpdir): """Test Lease.abort() with blocked socket. If the behavior this test is looking for is missing (a raised error for nonblock write timeout), this test will hang indefinitely on a blocking socket read. """ _make_lease(tmpdir, 123) with _abort_socket_norecv(tmpdir, 123): expired = list(leasing.leases_iter(str(tmpdir))) assert len(expired) == 1 lease = expired[0] with pytest.raises(socket.error): while True: lease.abort()
def _leases_dict(jobdir): """Convenience method for tests.""" return {lease.id: lease for lease in leasing.leases_iter(jobdir)}