diff options
| author | yo momma <shutup@oops.wtf> | 2026-02-04 19:25:03 +0000 |
|---|---|---|
| committer | yo momma <shutup@oops.wtf> | 2026-02-04 19:25:03 +0000 |
| commit | 75cf2a9c3cd925d2d8de4b5ef98bdd55c29e9861 (patch) | |
| tree | 457640db50cd62bac0649119abed37c3bdeb2fe7 /test/humpfm/load_test.clj | |
| parent | ad4d74ea45be6b227027588f6515fb22fafc335a (diff) | |
Rebrand: rename dump assets/templates to hump
Diffstat (limited to 'test/humpfm/load_test.clj')
| -rwxr-xr-x | test/humpfm/load_test.clj | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/test/humpfm/load_test.clj b/test/humpfm/load_test.clj new file mode 100755 index 0000000..3196f1c --- /dev/null +++ b/test/humpfm/load_test.clj @@ -0,0 +1,112 @@ +(ns humpfm.load-test + (:import org.postgresql.ds.PGPoolingDataSource) + (:use clojure.contrib.json.read + clojure.contrib.json.write + clojure.contrib.seq-utils + clojure.contrib.sql + humpfm.millstone)) + + +(let [db-host "localhost" + db-name "humpfm" + db-user "postgres" + db-pass "root"] + (def *db* {:datasource (doto (new PGPoolingDataSource) + (.setServerName db-host) + (.setDatabaseName db-name) + (.setUser db-user) + (.setPassword db-pass) + (.setMaxConnections 3))})) + +(def userlist-query " +select u.nick, u.hash +from users u, messages m +where u.user_id = m.user_id +and u.user_id not in + (select user_id from mutes where (set_on + duration < now())) +group by u.nick, u.hash +having count(*) > 50 +order by count(*) desc +") + +(print "Fetching userlist: ") +(def userlist (time + (with-connection *db* + (with-query-results rs [userlist-query] + (doall rs))))) + + +(def sample-messages-query " +select content +from messages +order by random() +limit 100 +") + +(print "Fetching messages: ") +(def message-contents (time + (with-connection *db* + (with-query-results rs [sample-messages-query] + (doall (map :content rs)))))) + +(defn login-client [] + (let [user-info (rand-elt userlist) + params (select-keys user-info [:nick :hash])] + (do-setup-request! "/login" + :params params + :method "GET"))) + +(defn rand-nick [] + (:nick (rand-elt userlist))) + +(defn load-profile [] + (do-request! (str "/" (rand-nick)) + :label "profile")) + +(defn load-popular-profile [] + (do-request! (str "/" (rand-nick)) + :label "popular-profile")) + +(defn load-popular-popular [] + (do-request! (str "/" (rand-elt ["ryder" "jeanette"]) "/popular") + :label "popular-popular")) + +(defn load-popular [] + (do-request! (str "/" (rand-nick) "/popular") + :label "popular")) + +(defn chat [] + (do-request! "/test/chat")) + +(defn refresh [] + (let [params {:since (- (System/currentTimeMillis) 2000) + :room "test"}] + (do-request! "/refresh" + :params params + :method "GET") + (Thread/sleep 1000))) + +(defn post-msg [] + (let [params {:content (rand-elt message-contents) + :room "test"}] + (do-request! "/msg" + :params params + :method "POST"))) + +(def test-spec {:server "http://localhost:8080" + :clients 75 + :requests 10000 + :max-latency 1000 + :setup-func login-client + :funcs [[55 refresh] + [10 load-popular] + [10 load-profile] + [3 load-popular-popular] + [3 load-popular-profile] + [3 chat] + [5 post-msg]] + :frequency 1 + }) + +(grind! test-spec) +(System/exit 0)
\ No newline at end of file |
