Skip to content

Commit 9c8566e

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

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)