Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
refactor(messagequeue): rename ambigous channel
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed Jun 5, 2021
1 parent cf7189e commit f60e47c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions internal/messagequeue/donthavetimeoutmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ type dontHaveTimeoutMgr struct {
messageLatency *latencyEwma
// timer used to wait until want at front of queue expires
checkForTimeoutsTimer *clock.Timer
// used for testing -- signal when a scheduled timeout check has happened
signal chan struct{}
// used for testing -- timeoutsTriggered when a scheduled dont have timeouts were triggered
timeoutsTriggered chan struct{}
}

// newDontHaveTimeoutMgr creates a new dontHaveTimeoutMgr
Expand All @@ -107,7 +107,7 @@ func newDontHaveTimeoutMgrWithParams(
messageLatencyMultiplier int,
maxExpectedWantProcessTime time.Duration,
clock clock.Clock,
signal chan struct{}) *dontHaveTimeoutMgr {
timeoutsTriggered chan struct{}) *dontHaveTimeoutMgr {

ctx, shutdown := context.WithCancel(context.Background())
mqp := &dontHaveTimeoutMgr{
Expand All @@ -124,7 +124,7 @@ func newDontHaveTimeoutMgrWithParams(
messageLatencyMultiplier: messageLatencyMultiplier,
maxExpectedWantProcessTime: maxExpectedWantProcessTime,
onDontHaveTimeout: onDontHaveTimeout,
signal: signal,
timeoutsTriggered: timeoutsTriggered,
}

return mqp
Expand Down Expand Up @@ -351,8 +351,8 @@ func (dhtm *dontHaveTimeoutMgr) fireTimeout(pending []cid.Cid) {
dhtm.onDontHaveTimeout(pending)

// signal a timeout fired
if dhtm.signal != nil {
dhtm.signal <- struct{}{}
if dhtm.timeoutsTriggered != nil {
dhtm.timeoutsTriggered <- struct{}{}
}
}

Expand Down
56 changes: 28 additions & 28 deletions internal/messagequeue/donthavetimeoutmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func TestDontHaveTimeoutMgrTimeout(t *testing.T) {
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
tr := timeoutRecorder{}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})
dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, signal)
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand All @@ -106,7 +106,7 @@ func TestDontHaveTimeoutMgrTimeout(t *testing.T) {
// Wait until after the expected timeout
clock.Add(20 * time.Millisecond)

<-signal
<-timeoutsTriggered

// At this stage first set of keys should have timed out
if tr.timedOutCount() != len(firstks) {
Expand All @@ -118,7 +118,7 @@ func TestDontHaveTimeoutMgrTimeout(t *testing.T) {
// Sleep until the second set of keys should have timed out
clock.Add(expectedTimeout + 10*time.Millisecond)

<-signal
<-timeoutsTriggered

// At this stage all keys should have timed out. The second set included
// the first set of keys, but they were added before the first set timed
Expand All @@ -138,9 +138,9 @@ func TestDontHaveTimeoutMgrCancel(t *testing.T) {
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
tr := timeoutRecorder{}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})
dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, signal)
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand All @@ -156,7 +156,7 @@ func TestDontHaveTimeoutMgrCancel(t *testing.T) {
// Wait for the expected timeout
clock.Add(expectedTimeout)

<-signal
<-timeoutsTriggered

// At this stage all non-cancelled keys should have timed out
if tr.timedOutCount() != len(ks)-cancelCount {
Expand All @@ -174,10 +174,10 @@ func TestDontHaveTimeoutWantCancelWant(t *testing.T) {
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
tr := timeoutRecorder{}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, signal)
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand All @@ -199,7 +199,7 @@ func TestDontHaveTimeoutWantCancelWant(t *testing.T) {
// Wait till after initial timeout
clock.Add(10 * time.Millisecond)

<-signal
<-timeoutsTriggered

// At this stage only the key that was never cancelled should have timed out
if tr.timedOutCount() != 1 {
Expand All @@ -209,7 +209,7 @@ func TestDontHaveTimeoutWantCancelWant(t *testing.T) {
// Wait till after added back key should time out
clock.Add(latency)

<-signal
<-timeoutsTriggered

// At this stage the key that was added back should also have timed out
if tr.timedOutCount() != 2 {
Expand All @@ -226,10 +226,10 @@ func TestDontHaveTimeoutRepeatedAddPending(t *testing.T) {
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
tr := timeoutRecorder{}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, signal)
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand All @@ -242,7 +242,7 @@ func TestDontHaveTimeoutRepeatedAddPending(t *testing.T) {
// Wait for the expected timeout
clock.Add(latency + 5*time.Millisecond)

<-signal
<-timeoutsTriggered

// At this stage all keys should have timed out
if tr.timedOutCount() != len(ks) {
Expand All @@ -260,10 +260,10 @@ func TestDontHaveTimeoutMgrMessageLatency(t *testing.T) {
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
tr := timeoutRecorder{}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
dontHaveTimeout, maxTimeout, latMultiplier, msgLatencyMultiplier, expProcessTime, clock, signal)
dontHaveTimeout, maxTimeout, latMultiplier, msgLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestDontHaveTimeoutMgrMessageLatency(t *testing.T) {
// Give the queue some time to process the updates
clock.Add(5 * time.Millisecond)

<-signal
<-timeoutsTriggered

if tr.timedOutCount() != len(ks) {
t.Fatal("expected keys to timeout")
Expand All @@ -307,10 +307,10 @@ func TestDontHaveTimeoutMgrMessageLatencyMax(t *testing.T) {
tr := timeoutRecorder{}
msgLatencyMultiplier := 1
testMaxTimeout := time.Millisecond * 10
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
dontHaveTimeout, testMaxTimeout, pingLatencyMultiplier, msgLatencyMultiplier, maxExpectedWantProcessTime, clock, signal)
dontHaveTimeout, testMaxTimeout, pingLatencyMultiplier, msgLatencyMultiplier, maxExpectedWantProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand All @@ -324,7 +324,7 @@ func TestDontHaveTimeoutMgrMessageLatencyMax(t *testing.T) {
// Sleep until just after the maximum timeout
clock.Add(testMaxTimeout + 5*time.Millisecond)

<-signal
<-timeoutsTriggered

// Keys should have timed out
if tr.timedOutCount() != len(ks) {
Expand All @@ -343,10 +343,10 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) {
clock := clock.NewMock()
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged, err: fmt.Errorf("ping error")}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
defaultTimeout, dontHaveTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, signal)
defaultTimeout, dontHaveTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand All @@ -365,7 +365,7 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) {
// Sleep until after the expected timeout
clock.Add(10 * time.Millisecond)

<-signal
<-timeoutsTriggered

// Now the keys should have timed out
if tr.timedOutCount() != len(ks) {
Expand All @@ -383,10 +383,10 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfLatencyLonger(t *testing.T) {
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
tr := timeoutRecorder{}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
defaultTimeout, dontHaveTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, signal)
defaultTimeout, dontHaveTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand All @@ -405,7 +405,7 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfLatencyLonger(t *testing.T) {
// Sleep until after the default timeout
clock.Add(defaultTimeout * 2)

<-signal
<-timeoutsTriggered

// Now the keys should have timed out
if tr.timedOutCount() != len(ks) {
Expand All @@ -422,10 +422,10 @@ func TestDontHaveTimeoutNoTimeoutAfterShutdown(t *testing.T) {
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
tr := timeoutRecorder{}
signal := make(chan struct{})
timeoutsTriggered := make(chan struct{})

dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, signal)
dontHaveTimeout, maxTimeout, latMultiplier, messageLatencyMultiplier, expProcessTime, clock, timeoutsTriggered)
dhtm.Start()
defer dhtm.Shutdown()
<-pinged
Expand Down

0 comments on commit f60e47c

Please sign in to comment.