Spinoco / fs2-http

Http Server and client using fs2
MIT License
135 stars 26 forks source link

Use `maxUnanswered` parameter in ws pings #18

Open wedens opened 7 years ago

wedens commented 7 years ago

It was unused.

Also deleted unused flag parameter.

pchlupacek commented 7 years ago

@wedens thanks for this. Any chance you can drop in test verifying the behaviour? Thanks

wedens commented 7 years ago

I'll try to do that. Should I just add tests for controlStream to WebSocketSpec ?

pchlupacek commented 7 years ago

yes, that would be awesome @wedens.

wedens commented 7 years ago

Sorry, I don't know how to implement such test :/

My best attempt so far was something ridiculous like:

  property("fail-on-unanswered-pings") = secure {
    val s = Stream.eval(async.unboundedQueue[Task, Unit]).flatMap { pingsQ =>
      Stream.eval(async.unboundedQueue[Task, PingPong]).flatMap { pongsQ =>
        val s = time.awakeEvery[Task](1.second).mapAccumulate(0) {
          case (x, _) if x >= 3 =>
            val s = Stream.eval_(pingsQ.enqueue1(()))
            (x + 1, s)
          case (x, _) =>
            val s = Stream.eval_(pingsQ.enqueue1(())) ++
              Stream.eval_(pongsQ.enqueue1(PingPong.Pong))
            (x + 1, s)
        }.flatMap(_._2)

        val s0 = WebSocket.impl.controlStream(pongsQ.dequeue, pingsQ.dequeue, 3)

        s mergeHaltR s0
      }
    }

    Prop.throws(classOf[Throwable]) {
      s.run.unsafeRun ?= (())
    }
  }