Commit d92d4804 authored by Jeromy's avatar Jeromy

improve cleaning up in dht tests.

parent f874e866
...@@ -107,6 +107,8 @@ func TestPing(t *testing.T) { ...@@ -107,6 +107,8 @@ func TestPing(t *testing.T) {
dhtA.Start() dhtA.Start()
dhtB.Start() dhtB.Start()
defer dhtA.Halt()
defer dhtB.Halt()
_, err = dhtA.Connect(addrB) _, err = dhtA.Connect(addrB)
if err != nil { if err != nil {
...@@ -118,9 +120,6 @@ func TestPing(t *testing.T) { ...@@ -118,9 +120,6 @@ func TestPing(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
dhtA.Halt()
dhtB.Halt()
} }
func TestValueGetSet(t *testing.T) { func TestValueGetSet(t *testing.T) {
...@@ -153,6 +152,8 @@ func TestValueGetSet(t *testing.T) { ...@@ -153,6 +152,8 @@ func TestValueGetSet(t *testing.T) {
dhtA.Start() dhtA.Start()
dhtB.Start() dhtB.Start()
defer dhtA.Halt()
defer dhtB.Halt()
errsa := dhtA.network.GetErrChan() errsa := dhtA.network.GetErrChan()
errsb := dhtB.network.GetErrChan() errsb := dhtB.network.GetErrChan()
...@@ -187,6 +188,11 @@ func TestProvides(t *testing.T) { ...@@ -187,6 +188,11 @@ func TestProvides(t *testing.T) {
u.Debug = false u.Debug = false
addrs, _, dhts := setupDHTS(4, t) addrs, _, dhts := setupDHTS(4, t)
defer func() {
for i := 0; i < 4; i++ {
dhts[i].Halt()
}
}()
_, err := dhts[0].Connect(addrs[1]) _, err := dhts[0].Connect(addrs[1])
if err != nil { if err != nil {
...@@ -228,15 +234,16 @@ func TestProvides(t *testing.T) { ...@@ -228,15 +234,16 @@ func TestProvides(t *testing.T) {
if len(provs) != 1 { if len(provs) != 1 {
t.Fatal("Didnt get back providers") t.Fatal("Didnt get back providers")
} }
for i := 0; i < 4; i++ {
dhts[i].Halt()
}
} }
func TestLayeredGet(t *testing.T) { func TestLayeredGet(t *testing.T) {
u.Debug = false u.Debug = false
addrs, _, dhts := setupDHTS(4, t) addrs, _, dhts := setupDHTS(4, t)
defer func() {
for i := 0; i < 4; i++ {
dhts[i].Halt()
}
}()
_, err := dhts[0].Connect(addrs[1]) _, err := dhts[0].Connect(addrs[1])
if err != nil { if err != nil {
...@@ -274,15 +281,17 @@ func TestLayeredGet(t *testing.T) { ...@@ -274,15 +281,17 @@ func TestLayeredGet(t *testing.T) {
t.Fatal("Got incorrect value.") t.Fatal("Got incorrect value.")
} }
for i := 0; i < 4; i++ {
dhts[i].Halt()
}
} }
func TestFindPeer(t *testing.T) { func TestFindPeer(t *testing.T) {
u.Debug = false u.Debug = false
addrs, peers, dhts := setupDHTS(4, t) addrs, peers, dhts := setupDHTS(4, t)
go func() {
for i := 0; i < 4; i++ {
dhts[i].Halt()
}
}()
_, err := dhts[0].Connect(addrs[1]) _, err := dhts[0].Connect(addrs[1])
if err != nil { if err != nil {
...@@ -311,8 +320,4 @@ func TestFindPeer(t *testing.T) { ...@@ -311,8 +320,4 @@ func TestFindPeer(t *testing.T) {
if !p.ID.Equal(peers[2].ID) { if !p.ID.Equal(peers[2].ID) {
t.Fatal("Didnt find expected peer.") t.Fatal("Didnt find expected peer.")
} }
for i := 0; i < 4; i++ {
dhts[i].Halt()
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment