|  |  |  | @ -100,6 +100,7 @@ type WebsocketTester struct { | 
			
		
	
		
			
				
					|  |  |  |  | 	mtx             sync.Mutex | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | // ReadJSON reads the next pending message from the "client" into v
 | 
			
		
	
		
			
				
					|  |  |  |  | func (ws *WebsocketTester) ReadJSON(v interface{}) error { | 
			
		
	
		
			
				
					|  |  |  |  | 	ws.mtx.Lock() | 
			
		
	
		
			
				
					|  |  |  |  | 	defer ws.mtx.Unlock() | 
			
		
	
	
		
			
				
					|  |  |  | @ -113,6 +114,7 @@ func (ws *WebsocketTester) ReadJSON(v interface{}) error { | 
			
		
	
		
			
				
					|  |  |  |  | 	return err | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | // WriteJSON "sends" a message, v, to the "client"
 | 
			
		
	
		
			
				
					|  |  |  |  | func (ws *WebsocketTester) WriteJSON(v interface{}) error { | 
			
		
	
		
			
				
					|  |  |  |  | 	ws.mtx.Lock() | 
			
		
	
		
			
				
					|  |  |  |  | 	defer ws.mtx.Unlock() | 
			
		
	
	
		
			
				
					|  |  |  | @ -122,16 +124,13 @@ func (ws *WebsocketTester) WriteJSON(v interface{}) error { | 
			
		
	
		
			
				
					|  |  |  |  | 		panic("wrong type written to WebsocketTester") | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	if len(m.Deltas) == 0 { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	ws.wroteMessages = append(ws.wroteMessages, m) | 
			
		
	
		
			
				
					|  |  |  |  | 	ws.wroteDeltas = append(ws.wroteDeltas, m.Deltas...) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	return nil | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | // ReceiveJSON queues a message to be sent to the client
 | 
			
		
	
		
			
				
					|  |  |  |  | func (ws *WebsocketTester) ReceiveJSON(v interface{}) error { | 
			
		
	
		
			
				
					|  |  |  |  | 	ws.mtx.Lock() | 
			
		
	
		
			
				
					|  |  |  |  | 	defer ws.mtx.Unlock() | 
			
		
	
	
		
			
				
					|  |  |  | @ -177,6 +176,7 @@ func TestDeltasSingle(t *testing.T) { | 
			
		
	
		
			
				
					|  |  |  |  | 	// so we expect to have written 0 messages
 | 
			
		
	
		
			
				
					|  |  |  |  | 	if len(client.wroteMessages) != 0 { | 
			
		
	
		
			
				
					|  |  |  |  | 		t.Errorf("client wrote %d messages, should have written %d", len(client.wroteMessages), 0) | 
			
		
	
		
			
				
					|  |  |  |  | 		t.Logf("%v", client.wroteMessages) | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// we received one, so make sure that's counted properly
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -268,13 +268,15 @@ func TestDeltasMulti(t *testing.T) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	doc, err := w.CH.editSession("content/" + title + ".md") | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		t.Fatal("couldn't establish docref:", err) | 
			
		
	
		
			
				
					|  |  |  |  | 		t.Fatal("couldn't establish edit session:", err) | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	go w.CH.handleDeltaConn(clients[0], doc) | 
			
		
	
		
			
				
					|  |  |  |  | 	go w.CH.handleDeltaConn(clients[1], doc) | 
			
		
	
		
			
				
					|  |  |  |  | 	go w.CH.handleDeltaConn(clients[2], doc) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	time.Sleep(100 * time.Millisecond) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	a := acedoc.Insert(0, 0, "a") | 
			
		
	
		
			
				
					|  |  |  |  | 	b := acedoc.Insert(0, 0, "b") | 
			
		
	
		
			
				
					|  |  |  |  | 	c := acedoc.Insert(0, 0, "c") | 
			
		
	
	
		
			
				
					|  |  |  | @ -283,12 +285,13 @@ func TestDeltasMulti(t *testing.T) { | 
			
		
	
		
			
				
					|  |  |  |  | 	clients[1].ReceiveJSON(w.CH.Message(b)) | 
			
		
	
		
			
				
					|  |  |  |  | 	clients[2].ReceiveJSON(w.CH.Message(c)) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	time.Sleep(400 * time.Millisecond) | 
			
		
	
		
			
				
					|  |  |  |  | 	time.Sleep(1000 * time.Millisecond) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	for i, client := range clients { | 
			
		
	
		
			
				
					|  |  |  |  | 		client.mtx.Lock() | 
			
		
	
		
			
				
					|  |  |  |  | 		// all clients should have "written" 2 deltas (could be the same
 | 
			
		
	
		
			
				
					|  |  |  |  | 		// message) that came from the other clients
 | 
			
		
	
		
			
				
					|  |  |  |  | 		t.Logf("client %d exists", i) | 
			
		
	
		
			
				
					|  |  |  |  | 		// all clients should have "written" 2 deltas out to their "browser"
 | 
			
		
	
		
			
				
					|  |  |  |  | 		// that came from the other clients
 | 
			
		
	
		
			
				
					|  |  |  |  | 		if len(client.wroteDeltas) != 2 { | 
			
		
	
		
			
				
					|  |  |  |  | 			t.Errorf("client %d wrote %d deltas, should have written 2", i, len(client.wroteDeltas)) | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
	
		
			
				
					|  |  |  | 
 |