-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
MESOP_CONCURRENT_UPDATES_ENABLED
env var (#868)
- Loading branch information
1 parent
483a2f8
commit a39bc6d
Showing
12 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import time | ||
|
||
import mesop as me | ||
|
||
|
||
@me.page(path="/concurrent_updates") | ||
def page(): | ||
me.text("concurrent_updates") | ||
me.button(label="Slow state update", on_click=slow_state_update) | ||
me.button(label="Fast state update", on_click=fast_state_update) | ||
me.text("Slow state: " + str(me.state(State).slow_state)) | ||
me.text("Fast state: " + str(me.state(State).fast_state)) | ||
|
||
|
||
@me.stateclass | ||
class State: | ||
slow_state: int = 0 | ||
fast_state: int = 0 | ||
|
||
|
||
def slow_state_update(e: me.ClickEvent): | ||
me.state(State).slow_state += 1 | ||
yield | ||
time.sleep(3) | ||
me.state(State).slow_state += 1 | ||
yield | ||
|
||
|
||
def fast_state_update(e: me.ClickEvent): | ||
me.state(State).fast_state += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {testInConcurrentUpdatesEnabledOnly} from './e2e_helpers'; | ||
import {expect} from '@playwright/test'; | ||
|
||
testInConcurrentUpdatesEnabledOnly('concurrent updates', async ({page}) => { | ||
await page.goto('/concurrent_updates'); | ||
await page.getByRole('button', {name: 'Slow state update'}).click(); | ||
await page.getByRole('button', {name: 'Fast state update'}).click(); | ||
await expect(page.getByText('Fast state: 1')).toBeVisible(); | ||
await expect(page.getByText('Slow state: 1')).toBeVisible(); | ||
|
||
// Slow state will update after the next render loop. | ||
await expect(page.getByText('Slow state: 2')).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import {test as base} from '@playwright/test'; | ||
|
||
export const testInProdOnly = base.extend({ | ||
// Skip all tests in this file if MESOP_DEBUG_MODE is 'true' | ||
// Skip this test if MESOP_DEBUG_MODE is 'true' | ||
page: async ({page}, use) => { | ||
if (process.env.MESOP_DEBUG_MODE === 'true') { | ||
base.skip(true, 'Skipping test in debug mode'); | ||
} | ||
await use(page); | ||
}, | ||
}); | ||
|
||
export const testInConcurrentUpdatesEnabledOnly = base.extend({ | ||
// Skip this test if MESOP_CONCURRENT_UPDATES_ENABLED is not 'true' | ||
page: async ({page}, use) => { | ||
if (process.env.MESOP_CONCURRENT_UPDATES_ENABLED !== 'true') { | ||
base.skip(true, 'Skipping test in concurrent updates disabled mode'); | ||
} | ||
await use(page); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Uses editor_cli which provides a faster development cycle than the regular "cli" target. | ||
(lsof -t -i:32123 | xargs kill) || true && \ | ||
MESOP_CONCURRENT_UPDATES_ENABLED=true \ | ||
MESOP_EXPERIMENTAL_EDITOR_TOOLBAR=true \ | ||
ibazel run //mesop/cli:editor_cli -- --path="mesop/mesop/example_index.py" --reload_demo_modules |