Skip to content

Replace external Wikipedia dependency in tests with local servers#160

Merged
sdsykes merged 1 commit intosdsykes:masterfrom
delphaber:replace-external-test-dependencies
Mar 7, 2026
Merged

Replace external Wikipedia dependency in tests with local servers#160
sdsykes merged 1 commit intosdsykes:masterfrom
delphaber:replace-external-test-dependencies

Conversation

@delphaber
Copy link
Copy Markdown
Contributor

Summary

  • The HTTPS and large-image tests relied on a live Wikipedia URL, causing flaky failures due to HTTP 429 rate limiting
  • Replaced with two local test servers:
    • SlowServer (raw TCP): sends JPEG header immediately then drip-feeds padding bytes with 0.5s delays, verifying FastImage reads only the minimum bytes needed rather than downloading the entire body
    • HTTPSServer (WEBrick + self-signed cert): exercises the real SSL codepath (use_ssl, verify_mode, etc.) without depending on external services
  • Added webrick as a dev dependency (needed for the HTTPS server)
  • Removed redundant constants (LargeImage, LargeImageInfo, LargeImageFetchLimit, HTTPSImage, HTTPSImageInfo) in favor of referencing GoodFixtures directly

Test plan

  • All 60 tests pass locally
  • No external network dependencies remain in the test suite (except test_should_raise_when_asked_to_when_file_does_not_exist and test_should_work_with_domains_with_underscores)
  • HTTPS test exercises real SSL handshake with self-signed certificate
  • Large image test confirms FastImage returns in <2s despite server needing 50+ seconds to send full body

🤖 Generated with Claude Code

@delphaber
Copy link
Copy Markdown
Contributor Author

I tried to remove the dependency on external URLs because wikipedia is rate limiting us.

With the help of Claude I created two fake web servers:

  • one web server that supports https (to test that FastImage is able to manage HTTPS urls)
  • one web server that after the initial headers it will stream padding in a slow way, so that we can test that FastImage only downloads the headers

It's a lot of code, I know, and these are more like "integration" test than unit tests.

What do you think? :)

@delphaber
Copy link
Copy Markdown
Contributor Author

There are 3 pending tests that are still in the queue. I think they are stuck, but I don't know why

@sdsykes
Copy link
Copy Markdown
Owner

sdsykes commented Mar 5, 2026

I think this could be a good approach. Odd that those tests are stuck though, but I could also maybe drop official support for 2.2 and below (over 12 years old now). I'll see if I can re-run the tests anyway.

@sdsykes
Copy link
Copy Markdown
Owner

sdsykes commented Mar 6, 2026

I've dropped the old versions, they relied on ubuntu 20 which is not available in github actions any more. It should hopefully work ok if you rebase.

The HTTPS and large-image tests relied on a live Wikipedia URL which
caused flaky failures due to HTTP 429 rate limiting. Replace with local
test servers: a raw TCP slow-drip server that verifies FastImage reads
only header bytes, and a WEBrick HTTPS server with a self-signed cert
that exercises the real SSL codepath.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@delphaber delphaber force-pushed the replace-external-test-dependencies branch from 98350df to 59ad39b Compare March 6, 2026 09:24
@delphaber
Copy link
Copy Markdown
Contributor Author

Rebased and now all tests are passing :), even ruby 4.0

@sdsykes sdsykes merged commit 8c8b349 into sdsykes:master Mar 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants