diff --git a/test/handlers/tickets_test.py b/test/handlers/tickets_test.py index 38efb4d1..11237c38 100644 --- a/test/handlers/tickets_test.py +++ b/test/handlers/tickets_test.py @@ -3,6 +3,7 @@ import http.client as http_client import json +import time import uuid import pytest @@ -399,24 +400,22 @@ def test_delete_all(srv): pytest.raises(KeyError, srv.auth.get, ticket["uuid"]) -def test_delete_active_connection(srv, tmpdir): - # Use short timeout to keep the tests fast. - srv.config.control.remove_timeout = 0.0001 - - filename = tmpdir.join("image") - # Note: must be big enough so the request remain active. - size = 1024**3 * 100 - with open(str(filename), 'wb') as image: - image.truncate(size) - ticket = testutil.create_ticket( - url="file://" + str(filename), ops=["read"], size=size) +def test_delete_conflict(srv, tmpdir, monkeypatch): + image = testutil.create_tempfile(tmpdir, "image", size=8 * 1024**2) + ticket = testutil.create_ticket(url="file://" + str(image)) srv.auth.add(ticket) - with http.ControlClient(srv.config) as c: - # Start a download, but read only 1 byte to make sure the operation - # becomes active but do not complete. - with http.RemoteClient(srv.config) as con: - remoteimage = con.get("/images/%(uuid)s" % ticket) - remoteimage.read(1) - res = c.delete("/tickets/%(uuid)s" % ticket) + # Use very short timeout to make the test fast. + monkeypatch.setattr(srv.config.control, "remove_timeout", 0.001) + + with http.RemoteClient(srv.config) as remote_client: + remote_client.get("/images/" + ticket["uuid"]) + + # Wait enough time to get the server connnection thread block on the + # client socket trying to write more data. + time.sleep(0.1) + + with http.ControlClient(srv.config) as control_client: + res = control_client.delete("/tickets/" + ticket["uuid"]) + res.read() assert res.status == 409