Skip to content

Commit e9a2bd3

Browse files
committed
Remove test dependency on /usr/share/dict/words
This file is not present by default on many systems and in fact, on systems like NixOS, it's not trivial to install at that path. Also, there is an unchecked reliance on that file to be at least 1e7 bytes long. If it is in fact shorter, the tests relying on it will just silently run with shorter inputs. Instead, just randomly generate printable ASCII characters and newlines. This seems to be of comparable performance and doesn't have the above problems.
1 parent 83850fb commit e9a2bd3

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323

2424
steps:
2525
- checkout
26-
- run: sudo apt-get install wbritish
2726
# Download and cache dependencies
2827
- restore_cache:
2928
keys:

test/aleph/http_test.clj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@
234234
@(http-get (str "https://localhost:" port "/" path)))))
235235
(str path "path failed")))))
236236

237-
(def words (slurp "/usr/share/dict/words"))
237+
(def characters
238+
(let [charset (conj (mapv char (range 32 127)) \newline)]
239+
(repeatedly #(rand-nth charset))))
238240

239241
(deftest test-bulk-requests
240242
(with-handler basic-handler
@@ -255,13 +257,13 @@
255257
(deftest test-echo
256258
(with-handler basic-handler
257259
(doseq [len [1e3 1e4 1e5 1e6 1e7]]
258-
(let [words (->> words (take len) (apply str))
260+
(let [characters (->> characters (take len) (apply str))
259261
body (:body
260262
@(http-put (str "http://localhost:" port "/echo")
261-
{:body words}))
263+
{:body characters}))
262264
body' (bs/to-string body)]
263-
(assert (== (min (count words) len) (count body')))
264-
(is (= words body'))))))
265+
(assert (== (min (count characters) len) (count body')))
266+
(is (= characters body'))))))
265267

266268
(deftest test-redirect
267269
(with-both-handlers basic-handler
@@ -293,11 +295,11 @@
293295
(deftest test-line-echo
294296
(with-handler basic-handler
295297
(doseq [len [1e3 1e4 1e5]]
296-
(let [words (->> words (take len) (apply str))
298+
(let [characters (->> characters (take len) (apply str))
297299
body (:body
298300
@(http-put (str "http://localhost:" port "/line_echo")
299-
{:body words}))]
300-
(is (= (.replace ^String words "\n" "") (bs/to-string body)))))))
301+
{:body characters}))]
302+
(is (= (.replace ^String characters "\n" "") (bs/to-string body)))))))
301303

302304
(deftest test-illegal-character-in-url
303305
(with-handler hello-handler

test/aleph/tcp_test.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
(finally
2020
(.close ^java.io.Closeable server#)))))
2121

22-
(def words (slurp "/usr/share/dict/words"))
23-
2422
(deftest test-echo
2523
(with-server (tcp/start-server echo-handler {:port 10001})
2624
(let [c @(tcp/client {:host "localhost", :port 10001})]

test/aleph/udp_test.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
(finally
1717
(.close ^java.io.Closeable server#)))))
1818

19-
(def words (slurp "/usr/share/dict/words"))
20-
2119
(deftest test-echo
2220
(let [s @(udp/socket {:port 10001, :epoll? true})]
2321
(s/put! s {:host "localhost", :port 10001, :message "foo"})

0 commit comments

Comments
 (0)