Skip to content

Commit f5cd5c2

Browse files
authored
Create a concurrency test to stress-test state is isolated across sessions (#657)
1 parent 9a8e251 commit f5cd5c2

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

.github/workflows/ci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ jobs:
4848
name: playwright-report
4949
path: playwright-report/
5050
retention-days: 30
51+
- name: Run playwright test (concurrency)
52+
run: yarn playwright test mesop/tests/e2e/concurrency/state_test.ts --repeat-each=48 --workers=16
53+
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
54+
if: always()
55+
with:
56+
name: playwright-report
57+
path: playwright-report/
58+
retention-days: 30
5159
- name: Run playwright test with memory state session
5260
run: MESOP_STATE_SESSION_BACKEND=memory yarn playwright test
5361
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3

mesop/examples/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from mesop.examples import buttons as buttons
77
from mesop.examples import checkbox_and_radio as checkbox_and_radio
88
from mesop.examples import composite as composite
9+
from mesop.examples import concurrency_state as concurrency_state
910
from mesop.examples import custom_font as custom_font
1011
from mesop.examples import dict_state as dict_state
1112
from mesop.examples import docs as docs

mesop/examples/concurrency_state.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import mesop as me
2+
3+
4+
@me.page(path="/concurrency_state")
5+
def page():
6+
me.text("concurrency_state")
7+
me.input(label="State input", on_input=on_input)
8+
me.text("Input: " + me.state(State).input)
9+
10+
11+
@me.stateclass
12+
class State:
13+
input: str
14+
15+
16+
def on_input(e: me.InputEvent):
17+
me.state(State).input = e.value
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* The purpose of this test is to ensure that sessions have proper
3+
* state isolation, particularly under high concurrency.
4+
*
5+
* Run test as:
6+
* yarn playwright test mesop/tests/e2e/concurrency/state_test.ts --repeat-each=48 --workers=16
7+
*/
8+
import {test, expect} from '@playwright/test';
9+
10+
test('state updates correctly', async ({page}) => {
11+
await page.goto('/concurrency_state');
12+
const randomString = generateRandomString(16);
13+
await page.getByLabel('State input').fill(randomString);
14+
await expect(page.getByText('Input: ' + randomString)).toBeVisible({
15+
timeout: 15000,
16+
});
17+
});
18+
19+
function generateRandomString(length: number) {
20+
const characters =
21+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
22+
let result = '';
23+
for (let i = 0; i < length; i++) {
24+
result += characters.charAt(Math.floor(Math.random() * characters.length));
25+
}
26+
return result;
27+
}

0 commit comments

Comments
 (0)