Skip to content

Commit

Permalink
🚨 add test / fix rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkyle committed Oct 8, 2020
1 parent 33bfc9a commit 6b8c49c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/dash.R
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ Dash <- R6::R6Class(
self$server$on('request', function(server, request, ...) {
timing_information <- self$server$get_data('timing-information')
dash_total <- timing_information[['__dash_server']]
timing_information[['__dash_server']][['dur']] <- round(as.numeric(Sys.time() - dash_total[['dur']]) * 1000)
timing_information[['__dash_server']][['dur']] <- round((as.numeric(Sys.time()) - dash_total[['dur']]) * 1000)

header_as_string <- list()

Expand Down
57 changes: 57 additions & 0 deletions tests/integration/test_callback_instrumentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import requests


app = """
library(dash)
library(dashHtmlComponents)
library(dashCoreComponents)
app <- Dash$new()
app$layout(htmlDiv(
list(
htmlDiv(children = "Hello world!",
id = "messageDiv"
),
htmlDiv(id = "emptyDiv")
)
)
)
app$callback(output = list(id="emptyDiv", property="children"),
params = list(input(id="messageDiv", property="children")),
function(y) {
app$callback_context.record_timing("pancakes", 1.23)
Sys.sleep(0.5)
return(y)
}
)
app$run_server(debug=TRUE)
"""

def test_rsci001_test_callback_instrumentation(dashr):
dashr.start_server(app)
dashr.wait_for_text_to_equal(
"#messageDiv",
"Hello world!"
)

response = requests.post(
"http://127.0.0.1:8050" + "/_dash-update-component",
json={
"output": "emptyDiv.children",
"outputs": {"id": "emptyDiv", "property": "children"},
"inputs": [{"id": "messageDiv", "property": "children", "value": 9}],
"changedPropIds": ["messageDiv.children"],
},
)
# eg 'Server-Timing': '__dash_server;dur=505, pancakes;dur=1230'
assert "Server-Timing" in response.headers

st = response.headers["Server-Timing"]
times = {k: int(float(v)) for k, v in [p.split(";dur=") for p in st.split(", ")]}
assert "pancakes" in times
assert times["pancakes"] == 1230
assert "__dash_server" in times
assert times["__dash_server"] >= 500 # 0.5 sec wait

0 comments on commit 6b8c49c

Please sign in to comment.