Example #1
0
def test_flush_repr():
    op = directio.Flush("/path")
    rep = repr(op)
    assert "Flush" in rep
    assert "path='/path'" in rep
    assert "done=0" in rep
    assert "active" in rep
Example #2
0
 def _flush(self, ticket_id, msg):
     ticket = tickets.authorize(ticket_id, "write", 0, 0)
     self.log.info("[%s] FLUSH ticket=%s", web.client_address(self.request),
                   ticket_id)
     op = directio.Flush(ticket.url.path, clock=self.clock)
     ticket.run(op)
     return web.response()
Example #3
0
def test_flush(tmpdir, monkeypatch):
    # This would be much cleaner when we add backend object implementing flush.
    fsync = os.fsync
    fsync_calls = [0]

    def counted_fsync(fd):
        fsync_calls[0] += 1
        fsync(fd)

    monkeypatch.setattr("os.fsync", counted_fsync)
    dst = tmpdir.join("src")
    dst.write("x" * directio.BUFFERSIZE)
    op = directio.Flush(str(dst))
    op.run()
    assert fsync_calls[0] == 1
Example #4
0
def test_flush_repr_active():
    op = directio.Flush("/path")
    op.close()
    assert "active" not in repr(op)
Example #5
0
def test_flush_close_twice(tmpfile):
    op = directio.Flush(str(tmpfile))
    op.run()
    op.close()  # should do nothing
    assert not op.active
Example #6
0
def test_flush_close_on_error():
    op = directio.Flush("/no/such/file")
    with pytest.raises(OSError):
        op.run()
    assert not op.active
Example #7
0
def test_flush_close_on_success(tmpfile):
    op = directio.Flush(str(tmpfile))
    op.run()
    assert not op.active
Example #8
0
def test_flush_busy():
    op = directio.Flush("/no/such/file")
    assert op.active
Example #9
0
 def _flush(self, ticket_id, msg):
     ticket = tickets.authorize(ticket_id, "write", 0, 0)
     self.log.info("Flushing %s for ticket %s", ticket.url.path, ticket_id)
     op = directio.Flush(ticket.url.path, clock=self.clock)
     ticket.run(op)
     return web.response()