Initial import (#1755695).

This commit is contained in:
Elliott Sales de Andrade 2019-09-27 17:43:12 -04:00
parent 8af781d980
commit 88d2cc094c
6 changed files with 26025 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/websocket_1.1.0.tar.gz

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
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

89
R-websocket.spec Normal file
View File

@ -0,0 +1,89 @@
%global packname websocket
%global rlibdir %{_libdir}/R/library
Name: R-%{packname}
Version: 1.1.0
Release: 1%{?dist}
Summary: 'WebSocket' Client Library
License: GPLv2
URL: https://CRAN.R-project.org/package=%{packname}
Source0: https://cran.r-project.org/src/contrib/%{packname}_%{version}.tar.gz
# For testing only.
Source1: echo.py
# https://github.com/rstudio/websocket/issues/59
Patch0001: 0001-Unbundle-websocketpp.patch
# For no-network testing.
Patch0002: 0002-Use-local-echo-server-for-testing-websockets.patch
# Here's the R view of the dependencies world:
# Depends:
# Imports: R-Rcpp, R-R6, R-later
# Suggests: R-testthat, R-knitr, R-rmarkdown
# LinkingTo: R-Rcpp, R-BH, R-AsioHeaders
# Enhances:
BuildRequires: R-devel
BuildRequires: tex(latex)
BuildRequires: R-Rcpp-devel
BuildRequires: R-R6
BuildRequires: R-later
BuildRequires: R-testthat
BuildRequires: R-knitr
BuildRequires: R-rmarkdown
BuildRequires: R-BH-devel
BuildRequires: R-AsioHeaders-devel
BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(websocketpp)
BuildRequires: python3dist(websockets)
%description
Provides a WebSocket client interface for R. WebSocket is a protocol for
low-overhead real-time communication:
<https://en.wikipedia.org/wiki/WebSocket>.
%prep
%setup -q -c -n %{packname}
pushd %{packname}
# Unbundle websocketpp
%patch0001 -p1
# Disable network usage
%patch0002 -p1
popd
%build
%install
mkdir -p %{buildroot}%{rlibdir}
%{_bindir}/R CMD INSTALL -l %{buildroot}%{rlibdir} %{packname}
test -d %{packname}/src && (cd %{packname}/src; rm -f *.o *.so)
rm -f %{buildroot}%{rlibdir}/R.css
%check
%{__python3} %SOURCE1 &
%{_bindir}/R CMD check %{packname}
%files
%dir %{rlibdir}/%{packname}
%doc %{rlibdir}/%{packname}/doc
%doc %{rlibdir}/%{packname}/html
%{rlibdir}/%{packname}/DESCRIPTION
%doc %{rlibdir}/%{packname}/NEWS.md
%{rlibdir}/%{packname}/INDEX
%{rlibdir}/%{packname}/NAMESPACE
%{rlibdir}/%{packname}/Meta
%{rlibdir}/%{packname}/R
%{rlibdir}/%{packname}/help
%dir %{rlibdir}/%{packname}/libs
%{rlibdir}/%{packname}/libs/%{packname}.so
%changelog
* Wed Sep 11 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 1.1.0-1
- initial package for Fedora

19
echo.py Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/python3
import asyncio
import websockets
async def echo(websocket, path):
while True:
try:
async for message in websocket:
await websocket.send(message)
except websockets.exceptions.ConnectionClosedError:
# Ignore too-large messages, sent as part of the test.
pass
server = websockets.serve(echo, 'localhost', 8765)
asyncio.get_event_loop().run_until_complete(server)
asyncio.get_event_loop().run_forever()

1
sources Normal file
View File

@ -0,0 +1 @@
SHA512 (websocket_1.1.0.tar.gz) = 9d34c8f0335ffb3cbbe35b06cc111d1249cf7255d4af9f082d40b0b271d204b9b0eca470bfa2e14d214f8f8e8eec0423addc0a2b93d9c8a146b5d0d0ad305e0b