Close channels

This commit is contained in:
Till Faelligen 2023-11-08 17:37:51 +01:00
parent fa3e0b540b
commit 478d34be06
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E

View file

@ -500,15 +500,18 @@ func TestDeviceListUpdaterIgnoreBlacklisted(t *testing.T) {
userIDToMutex: make(map[string]*sync.Mutex), userIDToMutex: make(map[string]*sync.Mutex),
} }
workerCh := make(chan spec.ServerName) workerCh := make(chan spec.ServerName)
defer close(workerCh)
updater.workerChans[0] = workerCh updater.workerChans[0] = workerCh
// happy case // happy case
alice := "@alice:localhost" alice := "@alice:localhost"
aliceCh := updater.assignChannel(alice) aliceCh := updater.assignChannel(alice)
defer updater.clearChannel(alice)
// failing case // failing case
bob := "@bob:" + unreachableServer bob := "@bob:" + unreachableServer
bobCh := updater.assignChannel(string(bob)) bobCh := updater.assignChannel(string(bob))
defer updater.clearChannel(string(bob))
expectedServers := map[spec.ServerName]struct{}{ expectedServers := map[spec.ServerName]struct{}{
"localhost": {}, "localhost": {},
@ -521,7 +524,7 @@ func TestDeviceListUpdaterIgnoreBlacklisted(t *testing.T) {
case "localhost": case "localhost":
delete(expectedServers, serverName) delete(expectedServers, serverName)
aliceCh <- true // unblock notifyWorkers aliceCh <- true // unblock notifyWorkers
case "notlocalhost": // this should not happen as it is "filtered" away by the blacklist case unreachableServer: // this should not happen as it is "filtered" away by the blacklist
unexpectedServers[serverName] = struct{}{} unexpectedServers[serverName] = struct{}{}
bobCh <- true bobCh <- true
default: default: