-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add proper concurrency support in websockets mode (#1036)
- Loading branch information
1 parent
660e1aa
commit 3714bd5
Showing
17 changed files
with
170 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
load("//build_defs:defaults.bzl", "py_library") | ||
|
||
package( | ||
default_visibility = ["//build_defs:mesop_internal"], | ||
) | ||
|
||
py_library( | ||
name = "env", | ||
srcs = glob(["*.py"]), | ||
) |
Empty file.
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,27 @@ | ||
import os | ||
|
||
AI_SERVICE_BASE_URL = os.environ.get( | ||
"MESOP_AI_SERVICE_BASE_URL", "http://localhost:43234" | ||
) | ||
|
||
MESOP_WEBSOCKETS_ENABLED = ( | ||
os.environ.get("MESOP_WEBSOCKETS_ENABLED", "false").lower() == "true" | ||
) | ||
|
||
MESOP_CONCURRENT_UPDATES_ENABLED = ( | ||
os.environ.get("MESOP_CONCURRENT_UPDATES_ENABLED", "false").lower() == "true" | ||
) | ||
|
||
if MESOP_WEBSOCKETS_ENABLED: | ||
print("Experiment enabled: MESOP_WEBSOCKETS_ENABLED") | ||
print("Auto-enabling MESOP_CONCURRENT_UPDATES_ENABLED") | ||
MESOP_CONCURRENT_UPDATES_ENABLED = True | ||
elif MESOP_CONCURRENT_UPDATES_ENABLED: | ||
print("Experiment enabled: MESOP_CONCURRENT_UPDATES_ENABLED") | ||
|
||
EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED = ( | ||
os.environ.get("MESOP_EXPERIMENTAL_EDITOR_TOOLBAR", "false").lower() == "true" | ||
) | ||
|
||
if EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED: | ||
print("Experiment enabled: EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED") |
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,35 @@ | ||
import time | ||
|
||
import mesop as me | ||
|
||
|
||
@me.page(path="/concurrent_updates_websockets") | ||
def page(): | ||
state = me.state(State) | ||
me.text("concurrent_updates_websockets") | ||
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(state.slow_state)) | ||
me.text("Fast state: " + str(state.fast_state)) | ||
if state.show_box: | ||
with me.box(): | ||
me.text("Box!") | ||
|
||
|
||
@me.stateclass | ||
class State: | ||
show_box: bool | ||
slow_state: bool | ||
fast_state: bool | ||
|
||
|
||
def slow_state_update(e: me.ClickEvent): | ||
time.sleep(3) | ||
me.state(State).show_box = True | ||
me.state(State).slow_state = True | ||
yield | ||
|
||
|
||
def fast_state_update(e: me.ClickEvent): | ||
me.state(State).show_box = True | ||
me.state(State).fast_state = True |
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
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
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,17 @@ | ||
import {testInWebSocketsEnabledOnly} from './e2e_helpers'; | ||
import {expect} from '@playwright/test'; | ||
|
||
testInWebSocketsEnabledOnly( | ||
'concurrent updates (websockets)', | ||
async ({page}) => { | ||
await page.goto('/concurrent_updates_websockets'); | ||
await page.getByRole('button', {name: 'Slow state update'}).click(); | ||
await page.getByRole('button', {name: 'Fast state update'}).click(); | ||
await expect(page.getByText('Fast state: true')).toBeVisible(); | ||
expect(await page.locator('text="Box!"').count()).toBe(1); | ||
await expect(page.getByText('Slow state: false')).toBeVisible(); | ||
await expect(page.getByText('Slow state: true')).toBeVisible(); | ||
// Make sure there isn't a second Box from the concurrent update. | ||
expect(await page.locator('text="Box!"').count()).toBe(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