105 lines
3.9 KiB
Diff
105 lines
3.9 KiB
Diff
From 5d360a0d22ed131ca0073a3f554b85ca78ae953c Mon Sep 17 00:00:00 2001
|
|
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
|
Date: Wed, 25 Sep 2019 05:43:49 -0400
|
|
Subject: [PATCH 2/2] Use local echo server for testing websockets.
|
|
|
|
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
|
---
|
|
tests/testthat/test-client.R | 21 +++++++++++----------
|
|
1 file changed, 11 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/tests/testthat/test-client.R b/tests/testthat/test-client.R
|
|
index ef1124b..226c100 100644
|
|
--- a/tests/testthat/test-client.R
|
|
+++ b/tests/testthat/test-client.R
|
|
@@ -1,7 +1,7 @@
|
|
|
|
test_that("Connection can't be defined with invalid maxMessageSize", {
|
|
- expect_error(WebSocket$new("ws://echo.websocket.org/", maxMessageSize=-1), "maxMessageSize must be a non-negative integer")
|
|
- expect_error(WebSocket$new("ws://echo.websocket.org/", maxMessageSize=1:2), "maxMessageSize must be a non-negative integer")
|
|
+ expect_error(WebSocket$new("ws://localhost:8765/", maxMessageSize=-1), "maxMessageSize must be a non-negative integer")
|
|
+ expect_error(WebSocket$new("ws://localhost:8765/", maxMessageSize=1:2), "maxMessageSize must be a non-negative integer")
|
|
})
|
|
|
|
check_later <- function(
|
|
@@ -44,7 +44,7 @@ test_that("small maxMessageSizes break simple connections", {
|
|
state <- NULL
|
|
didFail <- FALSE
|
|
|
|
- ws <- WebSocket$new("ws://echo.websocket.org/", maxMessageSize=2)
|
|
+ ws <- WebSocket$new("ws://localhost:8765/", maxMessageSize=2)
|
|
ws$onMessage(function(event) {
|
|
|
|
})
|
|
@@ -143,13 +143,13 @@ check_ws <- function(wsUrl) {
|
|
|
|
context("Basic WebSocket")
|
|
test_that("Basic websocket communication", {
|
|
- check_ws("ws://echo.websocket.org/")
|
|
+ check_ws("ws://localhost:8765/")
|
|
})
|
|
|
|
test_that("WebSocket object can be garbage collected", {
|
|
collected <- FALSE
|
|
local({
|
|
- ws <- WebSocket$new("ws://echo.websocket.org/")
|
|
+ ws <- WebSocket$new("ws://localhost:8765/")
|
|
ws$onOpen(function(event) {
|
|
ws$close()
|
|
})
|
|
@@ -167,7 +167,7 @@ test_that("WebSocket object can be garbage collected", {
|
|
})
|
|
|
|
test_that("Open is async", {
|
|
- ws <- WebSocket$new("ws://echo.websocket.org")
|
|
+ ws <- WebSocket$new("ws://localhost:8765")
|
|
ws$onOpen(function(event) {
|
|
ws$close()
|
|
})
|
|
@@ -193,7 +193,7 @@ test_that("Connection errors are reported", {
|
|
test_that("Connect can be delayed", {
|
|
# With autoConnect = TRUE (the default), you can miss the onOpen event
|
|
connected <- FALSE
|
|
- ws <- WebSocket$new("ws://echo.websocket.org")
|
|
+ ws <- WebSocket$new("ws://localhost:8765")
|
|
for (i in 1:100) {
|
|
later::run_now(0.1)
|
|
if (later::loop_empty() || ws$readyState() >= 1L) {
|
|
@@ -211,7 +211,7 @@ test_that("Connect can be delayed", {
|
|
# With autoConnect = FALSE, the open event is guaranteed not to fire
|
|
# until after connect() is called
|
|
connected <- FALSE
|
|
- ws <- WebSocket$new("ws://echo.websocket.org", autoConnect = FALSE)
|
|
+ ws <- WebSocket$new("ws://localhost:8765", autoConnect = FALSE)
|
|
for (i in 1:100) {
|
|
later::run_now(0.1)
|
|
if (later::loop_empty() || ws$readyState() >= 1L) {
|
|
@@ -234,7 +234,7 @@ test_that("Connect can be delayed", {
|
|
|
|
test_that("WebSocket can be closed before being opened or after being closed", {
|
|
onCloseCalled <- FALSE
|
|
- ws <- WebSocket$new("ws://echo.websocket.org")
|
|
+ ws <- WebSocket$new("ws://localhost:8765")
|
|
ws$close()
|
|
ws$onClose(function(event) {
|
|
onCloseCalled <<- TRUE
|
|
@@ -250,7 +250,7 @@ test_that("WebSocket event handlers can be registered more than once", {
|
|
a_called <- FALSE
|
|
b_called <- FALSE
|
|
c_called <- FALSE
|
|
- ws <- WebSocket$new("ws://echo.websocket.org")
|
|
+ ws <- WebSocket$new("ws://localhost:8765")
|
|
ws$onOpen(function(event) {
|
|
a_called <<- TRUE
|
|
})
|
|
@@ -274,5 +274,6 @@ test_that("WebSocket event handlers can be registered more than once", {
|
|
|
|
context("Basic SSL WebSocket")
|
|
test_that("Basic ssl websocket communication", {
|
|
+ skip_if_offline()
|
|
check_ws("wss://echo.websocket.org/")
|
|
})
|
|
--
|
|
2.21.0
|
|
|