1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00

Fix WebSocket mock (#300)

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
This commit is contained in:
Aleksandar Novaković 2018-05-23 23:33:15 +02:00 committed by Drasko DRASKOVIC
parent 64e71edf95
commit 4c8aeb395c

View File

@ -25,17 +25,18 @@ func (svc *mockService) Publish(msg mainflux.RawMessage) error {
return svc.pubError
}
svc.mutex.Lock()
defer svc.mutex.Unlock()
svc.subscriptions[msg.Channel].Messages <- msg
svc.mutex.Unlock()
return nil
}
func (svc *mockService) Subscribe(chanID uint64, channel ws.Channel) error {
svc.mutex.Lock()
defer svc.mutex.Unlock()
if _, ok := svc.subscriptions[chanID]; !ok {
return ws.ErrFailedSubscription
}
svc.mutex.Lock()
svc.subscriptions[chanID] = channel
svc.mutex.Unlock()
return nil
}