dispatch: channel reuse fix (#1237)

* Add test for dispatch channel reuse

* Dispatcher - make chans bidirectional

* No need to to keep the type assertion separate from the Get()

* Unexport Pipe's channel and add getter
This commit is contained in:
TaltaM
2023-06-21 04:33:40 +02:00
committed by GitHub
parent 97804a79da
commit db7441c723
6 changed files with 31 additions and 16 deletions

View File

@@ -183,7 +183,7 @@ func TestUnsubscribe(t *testing.T) {
}
// will return nil if not running
err = d.unsubscribe(nonEmptyUUID, make(<-chan interface{}))
err = d.unsubscribe(nonEmptyUUID, make(chan interface{}))
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
@@ -193,7 +193,7 @@ func TestUnsubscribe(t *testing.T) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
err = d.unsubscribe(nonEmptyUUID, make(<-chan interface{}))
err = d.unsubscribe(nonEmptyUUID, make(chan interface{}))
if !errors.Is(err, errDispatcherUUIDNotFoundInRouteList) {
t.Fatalf("received: '%v' but expected: '%v'", err, errDispatcherUUIDNotFoundInRouteList)
}
@@ -203,7 +203,7 @@ func TestUnsubscribe(t *testing.T) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
err = d.unsubscribe(id, make(<-chan interface{}))
err = d.unsubscribe(id, make(chan interface{}))
if !errors.Is(err, errChannelNotFoundInUUIDRef) {
t.Fatalf("received: '%v' but expected: '%v'", err, errChannelNotFoundInUUIDRef)
}
@@ -223,6 +223,16 @@ func TestUnsubscribe(t *testing.T) {
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
ch2, err := d.subscribe(id)
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
err = d.unsubscribe(id, ch2)
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}
}
func TestPublish(t *testing.T) {
@@ -416,7 +426,7 @@ func TestMux(t *testing.T) {
return
}
errChan <- nil
}(pipe.C, errChan, &wg)
}(pipe.c, errChan, &wg)
wg.Wait()
@@ -496,7 +506,7 @@ func TestMuxPublish(t *testing.T) {
}
}(mux)
<-pipe.C
<-pipe.Channel()
// Shut down dispatch system
err = d.stop()