From 3b7f992a2b779427cddbee14d905c5ad94ebfb57 Mon Sep 17 00:00:00 2001 From: jsattelb Date: Tue, 16 Jan 2024 16:49:05 -0500 Subject: [PATCH] Incorporate suggestions following C/R - Use testutil.create_tempfile to create temporary file - Use a smaller file, 8 MiB is enough to simulate the issu - Use monkeypatch.setattr() to modify global values for test_delete_conflict test - Use time.sleep() instead of reading one byte --- test/handlers/tickets_test.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) 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