forked from dunglas/mercure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadTest.scala
57 lines (50 loc) · 1.94 KB
/
LoadTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/** Load test for Mercure.
*
* 1. Grab Gatling 3 on https://gatling.io
* 2. Run path/to/gatling/bin/gatling.sh --simulations-folder .
*
* Available environment variables (all optional):
* - HUB_URL: the URL of the hub to test
* - JWT: the JWT to use for authenticating the publisher
* - SUBSCRIBERS: the number of concurrent subscribers
* - PUBLISHERS: the number of concurrent publishers
*/
package mercure
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.Properties
class LoadTest extends Simulation {
/** The hub URL */
val HubUrl = Properties.envOrElse("HUB_URL", "http://localhost:3001/hub" )
/** JWT to use to publish */
val Jwt = Properties.envOrElse("JWT", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJmb28iLCJiYXIiXSwicHVibGlzaCI6WyJmb28iXX19.afLx2f2ut3YgNVFStCx95Zm_UND1mZJ69OenXaDuZL8")
/** Number of concurrent subscribers to connect */
val ConcurrentSubscribers = Properties.envOrElse("SUBSCRIBERS", "10000").toInt
/** Number of concurent publishers */
val ConcurrentPublishers = Properties.envOrElse("PUBLISHERS", "2").toInt
val httpProtocol = http
.baseUrl(HubUrl)
val scenarioPublish = scenario("Publish")
.pause(2) // Wait for subscribers
.exec(
http("Publish")
.post("")
.header("Authorization", "Bearer "+Jwt)
.formParamMap(Map("topic" -> "http://example.com", "data" -> "Hi"))
.check(status.is(200))
)
val scenarioSubscribe = scenario("Subscribe")
.exec(
sse("Subscribe").connect("?topic=http://example.com")
.await(10)(
sse.checkMessage("Check content").check(regex("""(.*)Hi(.*)"""))
)
)
.pause(15)
.exec(sse("Close").close())
setUp(
scenarioSubscribe.inject(atOnceUsers(ConcurrentSubscribers)).protocols(httpProtocol),
scenarioPublish.inject(atOnceUsers(ConcurrentPublishers)).protocols(httpProtocol)
)
}