10 | Load testing example app
11 |
12 |
13 | Total entries: {{totalEntryCount}}
14 |
15 |
16 |
27 |
28 |
29 |
30 |
31 | {{#each entries}}
32 | -
33 |
34 | - {{name}}
35 | - {{createdAt}}
36 | - by: {{type}} {{ownerId}}
37 | -
38 |
39 |
40 | {{/each}}
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/sut/common.js:
--------------------------------------------------------------------------------
1 | Meteor.entries = new Meteor.Collection("entries");
2 |
--------------------------------------------------------------------------------
/sut/run:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | meteor --settings settings.json
3 |
--------------------------------------------------------------------------------
/sut/server/server.js:
--------------------------------------------------------------------------------
1 | ;(function () {
2 |
3 | //////////////////////////////////////////////////////////////////////
4 | // startup
5 | //////////////////////////////////////////////////////////////////////
6 |
7 | var settings = Meteor.settings || {},
8 | serverId = settings.serverId || Meteor.uuid(),
9 | entryIndex = 0;
10 |
11 | Meteor.startup(function () {
12 | Meteor.entries._ensureIndex({createdAt: -1});
13 |
14 | createServerEntries();
15 | });
16 |
17 |
18 | //////////////////////////////////////////////////////////////////////
19 | // methods
20 | //////////////////////////////////////////////////////////////////////
21 |
22 | Meteor.methods({
23 | addEntry: function (entry) {
24 | check(entry, Match.Optional({
25 | ownerId: String,
26 | name: String,
27 | type: String,
28 | createdAt: Match.Optional(Date)
29 | }));
30 |
31 | if (!entry) {
32 | entry = {
33 | ownerId: serverId,
34 | name: "entry-" + entryIndex++,
35 | type: "server"
36 | };
37 | }
38 |
39 | if (!entry.createdAt) {
40 | entry.createdAt = new Date()
41 | }
42 |
43 | return Meteor.entries.insert(entry);
44 | }
45 | });
46 |
47 |
48 | //////////////////////////////////////////////////////////////////////
49 | // publish
50 | //////////////////////////////////////////////////////////////////////
51 |
52 | Meteor.publish("entry-count", function () {
53 | var self = this,
54 | count = 0,
55 | docId = 1,
56 | initializing = true,
57 | handle;
58 |
59 | handle = Meteor.entries.find({}).observeChanges({
60 | added: function (id) {
61 | count++;
62 | if (!initializing)
63 | self.changed("total-entry-count", docId, {count: count});
64 | },
65 | removed: function (id) {
66 | count--;
67 | self.changed("total-entry-count", docId, {count: count});
68 | }
69 | // don't care about moved or changed
70 | });
71 |
72 | initializing = false;
73 | self.added("total-entry-count", docId, {count: count});
74 | self.ready();
75 |
76 | self.onStop(function () {
77 | handle.stop();
78 | });
79 | });
80 |
81 | Meteor.publish("latest-entries", function (limit) {
82 | check(limit, Match.Optional(Number));
83 |
84 | var settings = Meteor.settings || {},
85 | query = settings.query || {},
86 | sort = settings.sort,
87 | limit,
88 | options;
89 |
90 | limit = limit || settings.limit || 10,
91 |
92 | options = {
93 | sort: sort || { createdAt: -1 },
94 | limit: limit
95 | };
96 |
97 | return Meteor.entries.find(query, options);
98 | });
99 |
100 |
101 | //////////////////////////////////////////////////////////////////////
102 | // misc
103 | //////////////////////////////////////////////////////////////////////
104 |
105 | function createServerEntries () {
106 | var i = 0,
107 | entry;
108 |
109 | entry = Meteor.entries.findOne({ownerId: serverId});
110 |
111 | if (entry) {
112 | // already have entries for this server
113 | return;
114 | }
115 |
116 | console.log('creating default entries for server id ' + serverId);
117 |
118 | for (; i < 1000; i++) {
119 | entry = {
120 | ownerId: serverId,
121 | name: "entry-" + (i+1),
122 | type: "server",
123 | createdAt: new Date()
124 | };
125 | Meteor.entries.insert(entry);
126 | }
127 | } // end createServerEntries
128 |
129 |
130 | }());
131 |
--------------------------------------------------------------------------------
/sut/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "serverId": 1,
3 | "query": {},
4 | "sort": {"createdAt": -1},
5 | "limit": 10
6 | }
7 |
--------------------------------------------------------------------------------
/test/meteor_load_test/core_test.clj:
--------------------------------------------------------------------------------
1 | (ns meteor-load-test.core-test
2 | (:require [clojure.test :refer :all]
3 | [meteor-load-test.core :refer :all]))
4 |
5 | (deftest a-test
6 | (testing "Empty test"
7 | (is (= 1 1))))
8 |
--------------------------------------------------------------------------------
/test/meteor_load_test/initial_payload_test.clj:
--------------------------------------------------------------------------------
1 | (ns meteor-load-test.initial_payload_test
2 | (:require [clojure.test :refer :all]
3 | [conjure.core :refer :all]
4 | [meteor-load-test.initial_payload :refer :all]))
5 |
6 | (deftest test-drop-last-if
7 | (testing "drop-last-if"
8 | (let [s1 "/client/load-test.css?51243234"
9 | s2 "/client/load-test.css?51243234/"
10 | s3 "http://localhost:3000"
11 | s4 "http://localhost:3000/"]
12 | (is (= s1 (drop-last-if '\/ s1)))
13 | (is (= s1 (drop-last-if '\/ s2)))
14 | (is (= s3 (drop-last-if '\/ s3)))
15 | (is (= s3 (drop-last-if '\/ s4))))))
16 |
17 | (def html "
18 |