Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conntable tests #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions transport/conntable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func TestBasicStorage(t *testing.T) {
conn := makeTestConn()
table.Notify("foo", conn)

if table.GetConn("foo") != conn {
// Ensure it has been created.
if !testutils.Eventually(func() bool { return table.GetConn("foo") == conn }) {
t.FailNow()
}
}
Expand All @@ -44,10 +45,17 @@ func TestBasicExpiry(t *testing.T) {
defer table.Stop() // This currently panics due to issue #13.

table.Notify("bar", makeTestConn())

// Ensure it has been created.
if !testutils.Eventually(func() bool { return table.GetConn("bar") != nil }) {
t.FailNow()
}

timing.Elapse(c_SOCKET_EXPIRY)
timing.Elapse(time.Nanosecond)

if !testutils.Eventually(func() bool { return table.GetConn("bar") != nil }) {
// Ensure it has been expired.
if !testutils.Eventually(func() bool { return table.GetConn("bar") == nil }) {
t.FailNow()
}
}
Expand All @@ -60,12 +68,17 @@ func TestDoubleStorage(t *testing.T) {

conn1 := makeTestConn()
table.Notify("foo", conn1)

conn2 := makeTestConn()
table.Notify("bar", conn2)

if table.GetConn("foo") != conn1 {
// Ensure foo has been created.
if !testutils.Eventually(func() bool { return table.GetConn("foo") == conn1 }) {
t.FailNow()
} else if table.GetConn("bar") != conn2 {
}

// Ensure bar has been created.
if !testutils.Eventually(func() bool { return table.GetConn("bar") == conn2 }) {
t.FailNow()
}
}
Expand All @@ -80,7 +93,7 @@ func TestUpdate(t *testing.T) {
conn2 := makeTestConn()
table.Notify("foo", conn2)

if table.GetConn("foo") != conn2 {
if !testutils.Eventually(func() bool { return table.GetConn("foo") == conn2 }) {
t.FailNow()
}
}
Expand All @@ -94,17 +107,26 @@ func TestReuse1(t *testing.T) {

conn := makeTestConn()
table.Notify("foo", conn)

// Wait for connection to definitely exist.
if !testutils.Eventually(func() bool { return table.GetConn("foo") != nil }) {
t.Log("Connection foo couldn't be retrieved")
t.FailNow()
}

timing.Elapse(c_SOCKET_EXPIRY)
timing.Elapse(time.Nanosecond)

// Wait for connection to definitely expire.
if !testutils.Eventually(func() bool { return table.GetConn("foo") == nil }) {
t.Log("Connection foo was never nil")
t.FailNow()
}

// Re-store and retrieve.
table.Notify("foo", conn)
if table.GetConn("foo") != conn {
t.Log("Re-stored connection wasn't the one we put in")
t.FailNow()
}
}
Expand All @@ -117,17 +139,26 @@ func TestReuse2(t *testing.T) {
defer table.Stop()

table.Notify("foo", makeTestConn())

// Wait for connection to definitely exist.
if !testutils.Eventually(func() bool { return table.GetConn("foo") != nil }) {
t.Log("Connection foo couldn't be retrieved")
t.FailNow()
}

timing.Elapse(c_SOCKET_EXPIRY)
timing.Elapse(time.Nanosecond)

// Wait for connection to definitely expire.
if !testutils.Eventually(func() bool { return table.GetConn("foo") == nil }) {
t.Log("Connection foo was never nil")
t.FailNow()
}

conn2 := makeTestConn()
table.Notify("foo", conn2)
if table.GetConn("foo") != conn2 {
t.Log("Re-stored connection wasn't the one we put in")
t.FailNow()
}
}
Expand Down