Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pool/capabilities/comparator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestComparator_Compare(t *testing.T) {

comp := NewComparator()
for i, test := range dataProvider {
comp.Register(test.available)
result := comp.Compare(test.required, test.available)
assert.Equal(t, test.expectedResult, result, "Test #"+strconv.Itoa(i))
}
Expand Down
14 changes: 14 additions & 0 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,18 @@ func TestPool_fixNodeStatus_NegativeReserved(t *testing.T) {
a.Error(err)
}

func TestPool_SetBusyNodeDuration(t *testing.T) {
expected := time.Second
p := NewPool(nil, nil)
p.SetBusyNodeDuration(expected)
assert.Equal(t, expected, p.busyNodeDuration)
}

func TestPool_SetReservedNodeDuration(t *testing.T) {
expected := time.Second
p := NewPool(nil, nil)
p.SetReservedNodeDuration(expected)
assert.Equal(t, expected, p.reservedNodeDuration)
}

//---------------------------------
6 changes: 4 additions & 2 deletions pool/strategy/persistent/nodeHelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ func TestNodeHelper_removeAllSessions_Negative_Sessions_Error(t *testing.T) {

func TestNodeHelper_removeAllSessions_Negative_Sessions_MessageStatusNotOk(t *testing.T) {
cm := new(jsonwire.ClientMock)
cm.On("Address").Return("0.0.0.0")
nodeHelper := &nodeHelper{cm}
sessions := new(jsonwire.Sessions)
sessions.Status = 99999
cm.On("Sessions").Return(new(jsonwire.Sessions), errors.New("Err"))
cm.On("Sessions").Return(sessions, nil)
_, err := nodeHelper.removeAllSessions()
assert.NotNil(t, err)
}
Expand All @@ -78,6 +79,7 @@ func TestNodeHelper_removeAllSessions_Negative_CloseSession_Error(t *testing.T)

func TestNodeHelper_removeAllSessions_Negative_CloseSession_MessageStatusNotOk(t *testing.T) {
cm := new(jsonwire.ClientMock)
cm.On("Address").Return("0.0.0.0")
nodeHelper := &nodeHelper{cm}
sessions := new(jsonwire.Sessions)
sessions.Value = []struct {
Expand All @@ -89,7 +91,7 @@ func TestNodeHelper_removeAllSessions_Negative_CloseSession_MessageStatusNotOk(t
cm.On("Sessions").Return(sessions, nil)
message := new(jsonwire.Message)
message.Status = 999999
cm.On("CloseSession", mock.AnythingOfType("string")).Return(message, errors.New("Err"))
cm.On("CloseSession", mock.AnythingOfType("string")).Return(message, nil)
_, err := nodeHelper.removeAllSessions()
assert.NotNil(t, err)
}
5 changes: 3 additions & 2 deletions pool/strategy/persistent/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ func TestStrategy_Reserve_Negative_NotMatchCapabilities(t *testing.T) {
func TestStrategy_Reserve_Negative_ReserveAvailable(t *testing.T) {
sm := new(pool.StorageMock)
eError := errors.New("Error")
sm.On("GetAll").Return([]pool.Node{{}}, nil)
sm.On("GetAll").Return([]pool.Node{{CapabilitiesList: []capabilities.Capabilities{{}}}}, nil)
cm := new(capabilities.ComparatorMock)
cm.On("Register", mock.AnythingOfType("capabilities.Capabilities")).Return()
cm.On("Compare", mock.AnythingOfType("capabilities.Capabilities"), mock.AnythingOfType("capabilities.Capabilities")).Return(true)
sm.On("ReserveAvailable", mock.AnythingOfType("[]pool.Node")).Return([]pool.Node{}, eError)
sm.On("ReserveAvailable", mock.AnythingOfType("[]pool.Node")).Return(pool.Node{}, eError)
s := Strategy{storage: sm, capsComparator: cm}
_, err := s.Reserve(capabilities.Capabilities{})
assert.NotNil(t, err)
Expand Down
34 changes: 17 additions & 17 deletions storage/tests/mysql_test.go → storage/mysql/mysql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package mysql

import (
"crypto/rand"
Expand All @@ -7,7 +7,7 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/qa-dev/jsonwire-grid/pool"
"github.com/qa-dev/jsonwire-grid/storage/mysql"
"github.com/qa-dev/jsonwire-grid/storage/tests"
"github.com/rubenv/sql-migrate"
"os"
"strings"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (p PrepareMysql) CreateStorage() (pool.StorageInterface, func()) {
panic("Migrations failed, " + err.Error())
}

storage := mysql.NewMysqlStorage(db)
storage := NewMysqlStorage(db)
if err != nil {
panic("Error initialisation storage: " + err.Error())
}
Expand All @@ -96,72 +96,72 @@ func TestMain(m *testing.M) {

// TestMysqlStorage_Add see testStorage_Add
func TestMysqlStorage_Add(t *testing.T) {
testStorage_Add(t, mv)
tests.TestStorage_Add(t, mv)
}

// TestMysqlStorage_Add_Repeat see testStorage_Add_Repeat
func TestMysqlStorage_Add_Repeat(t *testing.T) {
testStorage_Add_Repeat(t, mv)
tests.TestStorage_Add_Repeat(t, mv)

}

// TestStorage_Add_Limit_Overflow see testStorage_Add_Limit_Overflow
func TestStorage_Add_Limit_Overflow(t *testing.T) {
testStorage_Add_Limit_Overflow(t, mv)
tests.TestStorage_Add_Limit_Overflow(t, mv)

}

// TestMysqlStorage_GetAll see testStorage_GetAll
func TestMysqlStorage_GetAll(t *testing.T) {
testStorage_GetAll(t, mv)
tests.TestStorage_GetAll(t, mv)
}

// TestMysqlStorage_GetByAddress see testStorage_GetByAddress
func TestMysqlStorage_GetByAddress(t *testing.T) {
testStorage_GetByAddress(t, mv)
tests.TestStorage_GetByAddress(t, mv)
}

// TestMysqlStorage_GetBySession see testStorage_GetBySession
func TestMysqlStorage_GetBySession(t *testing.T) {
testStorage_GetBySession(t, mv)
tests.TestStorage_GetBySession(t, mv)
}

// TestMysqlStorage_GetCountWithStatus see testStorage_GetCountWithStatus
func TestMysqlStorage_GetCountWithStatus(t *testing.T) {
testStorage_GetCountWithStatus(t, mv)
tests.TestStorage_GetCountWithStatus(t, mv)
}

// TestMysqlStorage_Remove see testStorage_Remove
func TestMysqlStorage_Remove(t *testing.T) {
testStorage_Remove(t, mv)
tests.TestStorage_Remove(t, mv)
}

// TestMysqlStorage_ReserveAvailable_Positive see testStorage_ReserveAvailable_Positive
func TestMysqlStorage_ReserveAvailable_Positive(t *testing.T) {
testStorage_ReserveAvailable_Positive(t, mv)
tests.TestStorage_ReserveAvailable_Positive(t, mv)
}

// TestMysqlStorage_ReserveAvailable_Negative see testStorage_ReserveAvailable_Negative
func TestMysqlStorage_ReserveAvailable_Negative(t *testing.T) {
testStorage_ReserveAvailable_Negative(t, mv)
tests.TestStorage_ReserveAvailable_Negative(t, mv)
}

// TestMysqlStorage_SetAvailable see testStorage_SetAvailable
func TestMysqlStorage_SetAvailable(t *testing.T) {
testStorage_SetAvailable(t, mv)
tests.TestStorage_SetAvailable(t, mv)
}

// TestMysqlStorage_SetBusy see testStorage_SetBusy
func TestMysqlStorage_SetBusy(t *testing.T) {
testStorage_SetBusy(t, mv)
tests.TestStorage_SetBusy(t, mv)
}

// TestMysqlStorage_UpdateAdderss_UpdatesValue see testStorage_UpdateAdderss_UpdatesValue
func TestMysqlStorage_UpdateAdderss_UpdatesValue(t *testing.T) {
testStorage_UpdateAdderss_UpdatesValue(t, mv)
tests.TestStorage_UpdateAdderss_UpdatesValue(t, mv)
}

// TestMysqlStorage_UpdateAdderss_ReturnsErrNotFound see testStorage_UpdateAdderss_ReturnsErrNotFound
func TestMysqlStorage_UpdateAdderss_ReturnsErrNotFound(t *testing.T) {
testStorage_UpdateAdderss_ReturnsErrNotFound(t, mv)
tests.TestStorage_UpdateAdderss_ReturnsErrNotFound(t, mv)
}
56 changes: 28 additions & 28 deletions storage/tests/comon_test.go → storage/tests/comon.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type PrepareInterface interface {
CreateStorage() (pool.StorageInterface, func())
}

// testStorage_Add проверка корректости добавления ноды в хранилище
func testStorage_Add(t *testing.T, p PrepareInterface) {
// TestStorage_Add проверка корректости добавления ноды в хранилище
func TestStorage_Add(t *testing.T, p PrepareInterface) {
t.Parallel()

storage, deferFunc := p.CreateStorage()
Expand Down Expand Up @@ -50,8 +50,8 @@ func testStorage_Add(t *testing.T, p PrepareInterface) {
//assert.Equal(t, expectedNode.CapabilitiesList, nodeList[0].CapabilitiesList) //todo: доделать
}

// testStorage_Add_Repeat проверка того что при повторном добавлении ноды вместо дублирования происходит корректный апдейт
func testStorage_Add_Repeat(t *testing.T, p PrepareInterface) {
// TestStorage_Add_Repeat проверка того что при повторном добавлении ноды вместо дублирования происходит корректный апдейт
func TestStorage_Add_Repeat(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -72,8 +72,8 @@ func testStorage_Add_Repeat(t *testing.T, p PrepareInterface) {
//todo: доделать capabilities
}

// testStorage_Add_Limit_Overflow проверка того что при переполнении лимита, запись не добавляется в хранилище
func testStorage_Add_Limit_Overflow(t *testing.T, p PrepareInterface) {
// TestStorage_Add_Limit_Overflow проверка того что при переполнении лимита, запись не добавляется в хранилище
func TestStorage_Add_Limit_Overflow(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -94,8 +94,8 @@ func testStorage_Add_Limit_Overflow(t *testing.T, p PrepareInterface) {
assert.Len(t, nodeList, limit, "Added more than "+strconv.Itoa(limit)+"one node")
}

// testStorage_GetAll проверка получения всех нод
func testStorage_GetAll(t *testing.T, p PrepareInterface) {
// TestStorage_GetAll проверка получения всех нод
func TestStorage_GetAll(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand Down Expand Up @@ -134,8 +134,8 @@ func testStorage_GetAll(t *testing.T, p PrepareInterface) {
}
}

// testStorage_GetByAddress проверка получения ноды по адресу
func testStorage_GetByAddress(t *testing.T, p PrepareInterface) {
// TestStorage_GetByAddress проверка получения ноды по адресу
func TestStorage_GetByAddress(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -155,8 +155,8 @@ func testStorage_GetByAddress(t *testing.T, p PrepareInterface) {

}

// testStorage_GetBySession проверка получения ноды по sessionId
func testStorage_GetBySession(t *testing.T, p PrepareInterface) {
// TestStorage_GetBySession проверка получения ноды по sessionId
func TestStorage_GetBySession(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -177,8 +177,8 @@ func testStorage_GetBySession(t *testing.T, p PrepareInterface) {

}

// testStorage_GetCountWithStatus проверка получения колличества нод с определенным статусом
func testStorage_GetCountWithStatus(t *testing.T, p PrepareInterface) {
// TestStorage_GetCountWithStatus проверка получения колличества нод с определенным статусом
func TestStorage_GetCountWithStatus(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -200,8 +200,8 @@ func testStorage_GetCountWithStatus(t *testing.T, p PrepareInterface) {
assert.Equal(t, count, 1)
}

// testStorage_Remove проверка удаления ноды
func testStorage_Remove(t *testing.T, p PrepareInterface) {
// TestStorage_Remove проверка удаления ноды
func TestStorage_Remove(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -216,8 +216,8 @@ func testStorage_Remove(t *testing.T, p PrepareInterface) {
assert.Error(t, err)
}

// testStorage_ReserveAvailable_Positive проверка резервирования ноды
func testStorage_ReserveAvailable_Positive(t *testing.T, p PrepareInterface) {
// TestStorage_ReserveAvailable_Positive проверка резервирования ноды
func TestStorage_ReserveAvailable_Positive(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -242,8 +242,8 @@ func testStorage_ReserveAvailable_Positive(t *testing.T, p PrepareInterface) {
assert.Equal(t, pool.NodeStatusReserved, node.Status, "Node not Reserved")
}

// testStorage_ReserveAvailable_Negative проверка резервирования ноды, при условии отсутствия доступных нод
func testStorage_ReserveAvailable_Negative(t *testing.T, p PrepareInterface) {
// TestStorage_ReserveAvailable_Negative проверка резервирования ноды, при условии отсутствия доступных нод
func TestStorage_ReserveAvailable_Negative(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -256,8 +256,8 @@ func testStorage_ReserveAvailable_Negative(t *testing.T, p PrepareInterface) {
assert.Error(t, err)
}

// testStorage_SetAvailable проверка изменения статуса ноды на Available
func testStorage_SetAvailable(t *testing.T, p PrepareInterface) {
// TestStorage_SetAvailable проверка изменения статуса ноды на Available
func TestStorage_SetAvailable(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -275,8 +275,8 @@ func testStorage_SetAvailable(t *testing.T, p PrepareInterface) {
assert.Equal(t, pool.NodeStatusAvailable, node.Status, "Node not Available")
}

// testStorage_SetBusy проверка изменения статуса ноды на Busy
func testStorage_SetBusy(t *testing.T, p PrepareInterface) {
// TestStorage_SetBusy проверка изменения статуса ноды на Busy
func TestStorage_SetBusy(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -296,8 +296,8 @@ func testStorage_SetBusy(t *testing.T, p PrepareInterface) {
assert.Equal(t, expectedSessionID, node.SessionID, "Not saved sessionID")
}

// testStorage_UpdateAdderss_UpdatesValue успешное обновления адреса ноды
func testStorage_UpdateAdderss_UpdatesValue(t *testing.T, p PrepareInterface) {
// TestStorage_UpdateAdderss_UpdatesValue успешное обновления адреса ноды
func TestStorage_UpdateAdderss_UpdatesValue(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand All @@ -316,8 +316,8 @@ func testStorage_UpdateAdderss_UpdatesValue(t *testing.T, p PrepareInterface) {
assert.Equal(t, expectedAddress, node.Address, "Not updated address")
}

// testStorage_UpdateAdderss_ReturnsErrNotFound попытка обновить несуществующую ноду
func testStorage_UpdateAdderss_ReturnsErrNotFound(t *testing.T, p PrepareInterface) {
// TestStorage_UpdateAdderss_ReturnsErrNotFound попытка обновить несуществующую ноду
func TestStorage_UpdateAdderss_ReturnsErrNotFound(t *testing.T, p PrepareInterface) {
t.Parallel()
storage, deferFunc := p.CreateStorage()
defer deferFunc()
Expand Down