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