Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue two purges for fastly surrogate keys #12771

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions tests/unit/cache/origin/test_fastly.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,17 @@ def test_purge_key_ok(self, monkeypatch):
"Fastly-Key": "an api key",
"Fastly-Soft-Purge": "1",
},
)
),
pretend.call(
"https://api.fastly.com/service/the-service-id/purge/one",
headers={
"Accept": "application/json",
"Fastly-Key": "an api key",
"Fastly-Soft-Purge": "1",
},
),
]
assert response.raise_for_status.calls == [pretend.call()]
assert response.raise_for_status.calls == [pretend.call(), pretend.call()]

@pytest.mark.parametrize("result", [{"status": "fail"}, {}])
def test_purge_key_unsuccessful(self, monkeypatch, result):
Expand Down
9 changes: 9 additions & 0 deletions warehouse/cache/origin/fastly.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import time
import urllib.parse

import requests
Expand Down Expand Up @@ -106,3 +107,11 @@ def purge_key(self, key):

if resp.json().get("status") != "ok":
raise UnsuccessfulPurgeError(f"Could not purge {key!r}")

time.sleep(2)

resp = requests.post(url, headers=headers)
resp.raise_for_status()

if resp.json().get("status") != "ok":
raise UnsuccessfulPurgeError(f"Could not double purge {key!r}")