diff --git a/docs/development.md b/docs/development.md index 4a3caab..603275b 100644 --- a/docs/development.md +++ b/docs/development.md @@ -31,3 +31,20 @@ vendor/bin/phpcs # CakePHP Coding Standard (Autofix: vendor/bin/phpcbf) ``` Vor jedem Commit müssen beide grün sein. `main` ist geschützt: Änderungen auf einem eigenen Branch pushen und per Pull Request mergen. + +## Lasttest (JMeter) + +`tests/load/plenario.jmx` simuliert Teilnehmende: Seite `/p/{code}` laden, kurz lesen, einmal auf der aktuellen +Auswahlfrage abstimmen (CSRF-Token, Folien- und Options-ID werden aus der Seite gelesen) und danach im +`Plenario.pollIntervalMs`-Takt `/p/{code}/state` abfragen. Jeder Thread hat eigene Cookies, ist also ein eigener Teilnehmer. + +```bash +jmeter -n -t tests/load/plenario.jmx -Jhost=localhost -Jport=8765 -Jcode=ABCD \ + -Jusers=200 -Jrampup=60 -Jduration=300 -l tmp/load.jtl -e -o tmp/load-report +``` + +Parameter: `protocol` (http), `host`, `port`, `code` (Join-Code), `users`, `rampup` (s), `duration` (s), `pollms` (2000). +Passende Testdaten legt `bin/cake polls seed` an: jeder Aufruf erzeugt eine **neue** Umfrage (neue ID und neuer Code) +mit je einer Folie pro interaktivem Typ; die erste Folie (Auswahlfrage) ist live und offen. `--json` liefert Code und +Admin-Link für Skripte, `--title`/`--email` passen die Daten an. Aufräumen: `bin/cake polls delete -y`. Alle Last kommt von einer IP: bei +`THROTTLE_VOTES_PER_MINUTE` (Standard 600) antwortet die Abstimmung sonst mit 429. Nur gegen eigene Instanzen testen. diff --git a/tests/load/plenario.jmx b/tests/load/plenario.jmx new file mode 100644 index 0000000..28bb3a8 --- /dev/null +++ b/tests/load/plenario.jmx @@ -0,0 +1,357 @@ + + + + + false + false + + + + PROTOCOL + ${__P(protocol,http)} + = + + + HOST + ${__P(host,localhost)} + = + + + PORT + ${__P(port,8765)} + = + + + CODE + ${__P(code,ABCD)} + = + + + POLL_MS + ${__P(pollms,2000)} + = + + + + + + + continue + + -1 + false + + ${__P(users,100)} + ${__P(rampup,60)} + true + ${__P(duration,300)} + + true + + + + + + + ${HOST} + ${PORT} + ${PROTOCOL} + UTF-8 + 10000 + 30000 + + + + + false + false + + + + + + User-Agent + JMeter-Lasttest + + + + + + + + PAGE_VERSION + NONE + = + + + VOTE_YES + 0 + = + + + + + + + + + + + /p/${CODE}/state + GET + false + true + + + + + + Accept + application/json + + + X-Requested-With + XMLHttpRequest + + + + + + + 200 + + + Assertion.response_code + false + 8 + + + + VERSION + $.version + 1 + NOT_FOUND + + + + ${POLL_MS} + 500 + + + + + + + ${__jexl3("${VERSION}" != "${PAGE_VERSION}" && "${VERSION}" != "NOT_FOUND")} + false + true + + + + + + + /p/${CODE} + GET + true + true + + + + + 200 + + + Assertion.response_code + false + 8 + + + + false + CSRF + name="csrf-token" content="([^"]+)" + $1$ + NOT_FOUND + 1 + + + + + groovy + + + true + def m = (html =~ re); m.find() ? m.group(1) : null } + +vars.put('PAGE_VERSION', first(/data-version="([^"]*)"/) ?: 'NOT_FOUND') + +def words = ['Zukunft', 'Teamgeist', 'Digital', 'Nachhaltig', 'Agil', 'Vertrauen', 'Mut', 'Tempo', 'Kommunikation', + 'Fortschritt', 'Respekt', 'Kreativ', 'Klarheit', 'Wandel', 'Zusammenhalt', 'Qualität'] +def texts = ['Mehr Praxisbeispiele bitte', 'Gerne kürzere Pausen', 'Alles gut so', 'Mehr Zeit für Fragen', + 'Das Thema ist spannend', 'Bitte langsamer sprechen'] + +def slideId = first(/name="slide_id"[^>]*value="(\d+)"/) +def parts = null +def kind = '' + +// Wer schon geantwortet hat, sieht kein Formular mehr (nur "Deine Antwort ist angekommen"). +if (slideId != null && !html.contains('class="done"')) { + def order = [] + def m = (html =~ /name="order\[\]" value="(\d+)"/) + while (m.find()) { order << m.group(1) } + def options = [] + m = (html =~ /name="(option_ids?(?:\[\])?)" value="(\d+)"/) + while (m.find()) { options << [m.group(1), m.group(2)] } + def values = [] + m = (html =~ /name="value" value="(\d+)"/) + while (m.find()) { values << m.group(1) } + + if (order) { + Collections.shuffle(order, rnd) + parts = order.collect { 'order%5B%5D=' + it } + kind = 'order' + } else if (options) { + def pick = options[rnd.nextInt(options.size())] + parts = [(pick[0].startsWith('option_ids') ? 'option_ids%5B%5D=' : 'option_id=') + pick[1]] + kind = 'choice' + } else if (values) { + parts = ['value=' + values[rnd.nextInt(values.size())]] + kind = 'scale' + } else if (html.contains('name="word"')) { + parts = ['word=' + words[rnd.nextInt(words.size())]] + kind = 'wordcloud' + } else if (html.contains('name="question"')) { + parts = ['question=' + java.net.URLEncoder.encode('Frage ' + rnd.nextInt(100000) + '?', 'UTF-8')] + kind = 'qa' + } else if (html.contains('name="text"')) { + parts = ['text=' + java.net.URLEncoder.encode(texts[rnd.nextInt(texts.size())], 'UTF-8')] + kind = 'open' + } +} + +if (parts != null) { + vars.put('VOTE_BODY', (['slide_id=' + slideId] + parts).join('&')) + vars.put('VOTE_KIND', kind) + vars.put('VOTE_YES', '1') +} else { + vars.put('VOTE_YES', '0') +} +]]> + + + + + + 1 + 0 + 0 + + + + 2000 + 6000 + + + + + + ${__jexl3("${VOTE_YES}" == "1")} + false + true + + + + true + + + + false + ${VOTE_BODY} + = + + + + /p/${CODE}/vote + POST + false + true + + + + + + Content-Type + application/x-www-form-urlencoded; charset=UTF-8 + + + X-CSRF-Token + ${CSRF} + + + X-Requested-With + XMLHttpRequest + + + + + + + + "ok":true + nicht mehr aktiv + + + Assertion.response_data + false + 34 + + + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + +