def test_transfered_inactive_empty_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) ticket.run(Operation(0, 0)) assert ticket.transferred() == 0 ticket.run(Operation(1000, 0)) assert ticket.transferred() == 0
def test_ticket_run(): ticket = Ticket(testutil.create_ticket(ops=["read"])) op = Operation(0, 100) assert ticket.transferred() == op.done assert op.done == 0 ticket.run(op) assert ticket.transferred() == op.done assert op.done == 100
def test_canceled_fail_run_before(): ticket = Ticket(testutil.create_ticket(ops=["read"])) ticket.cancel() op = Operation() # Running operations must fail. with pytest.raises(errors.AuthorizationError): ticket.run(op) # Operation was not run. assert op.done == 0
def test_canceled_fail_run_after(cfg): ticket = Ticket(testutil.create_ticket(ops=["read"]), cfg) class Operation: def __init__(self): self.done = False self.canceled = False def run(self): self.done = True ticket.cancel(timeout=0.001) def cancel(self): self.canceled = True op = Operation() # If ticket was canceled while ongoing operations are running, ticket run # will fail removing the operations. with pytest.raises(errors.AuthorizationError): ticket.run(op) assert op.done
def test_transferred_benchmark(concurrent): # Time trransferred call with multiple ongoing and completed operations. ticket = Ticket(testutil.create_ticket(ops=["read"])) calls = 10000 # Add some completed ranges - assume worst case when ranges are not # continues. for i in range(concurrent): ticket.run(Operation(i * 1000, 100)) # Add some ongoing operations - assume worst case when ranges are not # continues. for i in range(concurrent): ticket._add_operation(Operation(i * 1000 + 200, 100)) # Time transferred call - merging ongoing and completed ranges. start = time.monotonic() for i in range(calls): ticket.transferred() elapsed = time.monotonic() - start print("%d concurrent operations, %d calls in %.3f seconds (%d nsec/op)" % (concurrent, calls, elapsed, elapsed * 10**9 // calls))
def test_transferred_benchmark(cfg, workers): # Time trransferred call with multiple ongoing and completed operations. ticket = Ticket(testutil.create_ticket(ops=["read"]), cfg) ops = 10000 # Add some completed ranges - assume worst case when ranges are not # continues. for i in range(workers): ticket.run(Operation(i * 1000, 100)) # Add some ongoing operations - assume worst case when ranges are not # continues. for i in range(workers): ticket._add_operation(Operation(i * 1000 + 200, 100)) # Time transferred call - merging ongoing and completed ranges. start = time.monotonic() for i in range(ops): ticket.transferred() elapsed = time.monotonic() - start print("%d workers, %d ops, %.3f s, %.2f ops/s" % (workers, ops, elapsed, ops / elapsed))
def test_transfered_inactive_non_continuous_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) # Run 2 non-continutes operations ticket.run(Operation(0, 100)) ticket.run(Operation(200, 100)) assert ticket.transferred() == 200 # Run last operation filling the hole - with some overlap. ticket.run(Operation(80, 120)) assert ticket.transferred() == 300
def test_transfered_inactive_overlapping_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) ticket.run(Operation(0, 120)) assert ticket.transferred() == 120 ticket.run(Operation(100, 100)) assert ticket.transferred() == 200 ticket.run(Operation(180, 120)) assert ticket.transferred() == 300
def test_transfered_inactive_unordered_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) ticket.run(Operation(100, 100)) assert ticket.transferred() == 100 ticket.run(Operation(0, 100)) assert ticket.transferred() == 200 ticket.run(Operation(200, 100)) assert ticket.transferred() == 300