Skip to content

Commit

Permalink
Incorporate suggestions following C/R
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jsattelb committed Jan 16, 2024
1 parent 4ec2261 commit 3b7f992
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions test/handlers/tickets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import http.client as http_client
import json
import time
import uuid

import pytest
Expand Down Expand Up @@ -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

0 comments on commit 3b7f992

Please sign in to comment.