Skip to content

Commit 6b8c49c

Browse files
author
rpkyle
committed
🚨 add test / fix rounding
1 parent 33bfc9a commit 6b8c49c

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

R/dash.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ Dash <- R6::R6Class(
12721272
self$server$on('request', function(server, request, ...) {
12731273
timing_information <- self$server$get_data('timing-information')
12741274
dash_total <- timing_information[['__dash_server']]
1275-
timing_information[['__dash_server']][['dur']] <- round(as.numeric(Sys.time() - dash_total[['dur']]) * 1000)
1275+
timing_information[['__dash_server']][['dur']] <- round((as.numeric(Sys.time()) - dash_total[['dur']]) * 1000)
12761276

12771277
header_as_string <- list()
12781278

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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):
34+
dashr.start_server(app)
35+
dashr.wait_for_text_to_equal(
36+
"#messageDiv",
37+
"Hello world!"
38+
)
39+
40+
response = requests.post(
41+
"http://127.0.0.1:8050" + "/_dash-update-component",
42+
json={
43+
"output": "emptyDiv.children",
44+
"outputs": {"id": "emptyDiv", "property": "children"},
45+
"inputs": [{"id": "messageDiv", "property": "children", "value": 9}],
46+
"changedPropIds": ["messageDiv.children"],
47+
},
48+
)
49+
# eg 'Server-Timing': '__dash_server;dur=505, pancakes;dur=1230'
50+
assert "Server-Timing" in response.headers
51+
52+
st = response.headers["Server-Timing"]
53+
times = {k: int(float(v)) for k, v in [p.split(";dur=") for p in st.split(", ")]}
54+
assert "pancakes" in times
55+
assert times["pancakes"] == 1230
56+
assert "__dash_server" in times
57+
assert times["__dash_server"] >= 500 # 0.5 sec wait

0 commit comments

Comments
 (0)