tests/testthat/test-stream-server.R

context("stream-server")

test_that("will read and write messages over streams", {
  incoming <- tempfile()
  outgoing <- tempfile()
  server <- StreamServer$new(NULL, incoming, outgoing)

  request <- JsonRpcRequest$new(method = "manifest")
  jsonrpc <- request$serialize()
  stream_write_message(jsonrpc, incoming)
  expect_equal(server$read(), jsonrpc)

  response <- JsonRpcResponse$new(result = 42)
  jsonrpc <- response$serialize()
  server$write(jsonrpc)
  message <- stream_read_message(outgoing)
  expect_true(is.character(message))
  expect_equal(message, jsonrpc)
})
stencila/rasta documentation built on Oct. 12, 2021, 10:26 p.m.