t.Errorf("clientA wrote %d messages, should have written 0. clientB wrote %d, should have written 1",len(clientA.wroteMessages),len(clientB.wroteMessages))
}
// we received one via clientA and zero via clientB, so make sure
t.Errorf("clientA has %d messages, should have received 1; clientB has %d messages, should have received 0",len(clientA.received),len(clientB.received))
t.Errorf("clientA wrote %d messages, should have written 1. clientB wrote %d, should have written 1 (just from before)",len(clientA.wroteMessages),len(clientB.wroteMessages))
}
// we received zero (new) via clientA and one via clientB, so make sure
t.Errorf("clientA has %d messages, should have received 1; clientB has %d messages, should have received 1",len(clientA.received),len(clientB.received))
}
clientA.mtx.Unlock()
clientB.mtx.Unlock()
}
funcTestDeltasMulti(t*testing.T){
w:=NewWorld(t)
deferw.Clean()
consttitle="test"
_,err:=w.CH.NewContent(title,"")
iferr!=nil{
t.Fatal("couldn't create new content:",err)
}
clients:=[]*WebsocketTester{{},{},{}}
doc,err:=w.CH.client("content/"+title+".md")
iferr!=nil{
t.Fatal("couldn't establish docref:",err)
}
gow.CH.handleConn(clients[0],doc)
gow.CH.handleConn(clients[1],doc)
gow.CH.handleConn(clients[2],doc)
a:=acedoc.Insert(0,0,"a")
b:=acedoc.Insert(0,0,"b")
c:=acedoc.Insert(0,0,"c")
clients[0].ReceiveJSON(w.CH.Message(a))
clients[1].ReceiveJSON(w.CH.Message(b))
clients[2].ReceiveJSON(w.CH.Message(c))
time.Sleep(400*time.Millisecond)
fori,client:=rangeclients{
client.mtx.Lock()
// all clients should have "written" 2 deltas (could be the same
// message) that came from the other clients
iflen(client.wroteDeltas)!=2{
t.Errorf("client %d wrote %d deltas, should have written 2",i,len(client.wroteDeltas))
}
// all clients "received" 1 message from the "browser"
iflen(client.received)!=1{
t.Errorf("client %d has %d messages, should have received 1",i,len(client.received))