skipping pushing message to client if there are no messages; fixes flaky test and de-intensifies read loop

pull/8/head
Stephen Searles 7 years ago
parent 029d1ed5b3
commit e5d16dd2d5
  1. 10
      deltas.go
  2. 2
      doc_test.go

@ -92,8 +92,9 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
wroteMessagesCh := make(chan Message, 2)
client := doc.doc.Client(acedoc.DeltaHandlerFunc(func(ds []acedoc.Delta) error {
wroteMessagesCh <- Message{Deltas: ds}
return conn.WriteJSON(ch.Message(ds...))
m := ch.Message(ds...)
wroteMessagesCh <- m
return conn.WriteJSON(m)
}))
ch.mtx.Lock()
@ -119,6 +120,11 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
}
ch.ObserveLTime(message.LTime)
if len(message.Deltas) == 0 {
time.Sleep(10 * time.Microsecond)
continue
}
err = client.PushDeltas(message.Deltas...)
if err != nil {
errCh <- err

@ -233,7 +233,7 @@ func TestDeltasDouble(t *testing.T) {
// send the second message, via clientB
clientB.ReceiveJSON(w.CH.Message(acedoc.Insert(0, 0, "b")))
time.Sleep(200 * time.Millisecond)
time.Sleep(400 * time.Millisecond)
clientA.mtx.Lock()
clientB.mtx.Lock()

Loading…
Cancel
Save