forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: logic of add/delete in round robin strategy
* Duplicates could be added to a list of connections, which then cannot be deleted. * The delete function uses an address from a connection instead of argument value. It may lead to unexpected errors. Part of #208
- Loading branch information
1 parent
d7b0e43
commit 7645f40
Showing
2 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package connection_pool_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
. "github.com/tarantool/go-tarantool/connection_pool" | ||
) | ||
|
||
const ( | ||
validAddr1 = "x" | ||
validAddr2 = "y" | ||
) | ||
|
||
func TestRoundRobinAddDelete(t *testing.T) { | ||
rr := NewEmptyRoundRobin(10) | ||
|
||
addrs := []string{validAddr1, validAddr2} | ||
conns := []*tarantool.Connection{&tarantool.Connection{}, &tarantool.Connection{}} | ||
|
||
for i, addr := range addrs { | ||
rr.AddConn(addr, conns[i]) | ||
} | ||
|
||
for i, addr := range addrs { | ||
if conn := rr.DeleteConnByAddr(addr); conn != conns[i] { | ||
t.Errorf("Unexpected connection on address %s", addr) | ||
} | ||
} | ||
if !rr.IsEmpty() { | ||
t.Errorf("RoundRobin does not empty") | ||
} | ||
} | ||
|
||
func TestRoundRobinAddDuplicateDelete(t *testing.T) { | ||
rr := NewEmptyRoundRobin(10) | ||
|
||
conn1 := &tarantool.Connection{} | ||
conn2 := &tarantool.Connection{} | ||
|
||
rr.AddConn(validAddr1, conn1) | ||
rr.AddConn(validAddr1, conn2) | ||
|
||
if rr.DeleteConnByAddr(validAddr1) != conn2 { | ||
t.Errorf("Unexpected deleted connection") | ||
} | ||
if !rr.IsEmpty() { | ||
t.Errorf("RoundRobin does not empty") | ||
} | ||
if rr.DeleteConnByAddr(validAddr1) != nil { | ||
t.Errorf("Unexpected valued after second delition") | ||
} | ||
} | ||
|
||
|