Skip to content

Commit 878df44

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

File tree

2 files changed

+60
-1
lines changed

2 files changed

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

Comments
 (0)