|
| 1 | +from selenium.webdriver.support.select import Select |
| 2 | +from time import sleep |
| 3 | +import os, requests |
| 4 | + |
| 5 | + |
| 6 | +app = """ |
| 7 | + library(dash) |
| 8 | + library(dashHtmlComponents) |
| 9 | + library(dashCoreComponents) |
| 10 | +
|
| 11 | + app <- Dash$new() |
| 12 | +
|
| 13 | + app$layout(htmlDiv( |
| 14 | + list( |
| 15 | + htmlDiv(children = "Hello world!", |
| 16 | + id = "messageDiv" |
| 17 | + ), |
| 18 | + htmlDiv(id = "emptyDiv") |
| 19 | + ) |
| 20 | + ) |
| 21 | + ) |
| 22 | +
|
| 23 | + app$callback(output = list(id="emptyDiv", property="children"), |
| 24 | + params = list(input(id="messageDiv", property="children")), |
| 25 | + function(y) { |
| 26 | + app$callback_context.record_timing("pancakes", 1.23) |
| 27 | + Sys.sleep(0.5) |
| 28 | + return(y) |
| 29 | + } |
| 30 | + ) |
| 31 | +
|
| 32 | + app$run_server(debug=TRUE) |
| 33 | +""" |
| 34 | + |
| 35 | +def test_rstm001_test_meta(dashr): |
| 36 | + dashr.start_server(app) |
| 37 | + dashr.wait_for_text_to_equal( |
| 38 | + "#messageDiv", |
| 39 | + "Hello world!" |
| 40 | + ) |
| 41 | + |
| 42 | + response = requests.post( |
| 43 | + "http://127.0.0.1:8050" + "/_dash-update-component", |
| 44 | + json={ |
| 45 | + "output": "emptyDiv.children", |
| 46 | + "outputs": {"id": "emptyDiv", "property": "children"}, |
| 47 | + "inputs": [{"id": "messageDiv", "property": "children", "value": 9}], |
| 48 | + "changedPropIds": ["messageDiv.children"], |
| 49 | + }, |
| 50 | + ) |
| 51 | + # eg 'Server-Timing': '__dash_server;dur=505, pancakes;dur=1230' |
| 52 | + assert "Server-Timing" in response.headers |
| 53 | + |
| 54 | + st = response.headers["Server-Timing"] |
| 55 | + times = {k: int(float(v)) for k, v in [p.split(";dur=") for p in st.split(", ")]} |
| 56 | + assert "pancakes" in times |
| 57 | + assert times["pancakes"] == 1230 |
| 58 | + assert "__dash_server" in times |
| 59 | + assert times["__dash_server"] >= 500 # 0.5 sec wait |
0 commit comments