Skip to content

Commit

Permalink
Improvements from review
Browse files Browse the repository at this point in the history
- remove a TODO
- inline newSyncSession (only reference)
- defer the unlock for readability
  • Loading branch information
DrJosh9000 committed Jun 18, 2020
1 parent 781ddb5 commit 0b82e0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 9 additions & 14 deletions engine/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,6 @@ type syncSession struct {
notes chan *SyncNote
}

// newSyncSession returns an initialised synchronisation session.
func newSyncSession(node net.IP, id SyncSessionID) *syncSession {
return &syncSession{
id: id,
node: node,
desync: true,
startTime: time.Now(),
expiryTime: time.Now().Add(sessionDeadtime),
notes: make(chan *SyncNote, sessionNotesQueueSize),
}
}

// addNote adds a notification to the synchronisation session. If the notes
// channel is full the session is marked as desynchronised and the notification
// is discarded.
Expand Down Expand Up @@ -258,10 +246,17 @@ func newSyncServer(e *Engine) *syncServer {
// the provided node.
func (s *syncServer) newSession(node net.IP) *syncSession {
s.sessionLock.Lock()
session := newSyncSession(node, s.nextSessionID)
defer s.sessionLock.Unlock()
session := &syncSession{
id: s.nextSessionID,
node: node,
desync: true,
startTime: time.Now(),
expiryTime: time.Now().Add(sessionDeadtime),
notes: make(chan *SyncNote, sessionNotesQueueSize),
}
s.nextSessionID++
s.sessions[session.id] = session
s.sessionLock.Unlock()

return session
}
Expand Down
2 changes: 0 additions & 2 deletions engine/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ func TestSyncHeartbeats(t *testing.T) {
go server.run()
go client.run()

// TODO: Test we can disable and re-enable the client

// Enabling briefly shouldn't have time to get a heartbeat, but should get
// the initial desync.
client.enable()
Expand Down

0 comments on commit 0b82e0f

Please sign in to comment.