diff --git a/pool/capabilities/comparator_test.go b/pool/capabilities/comparator_test.go index 661d18d..2d0467c 100644 --- a/pool/capabilities/comparator_test.go +++ b/pool/capabilities/comparator_test.go @@ -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)) } diff --git a/pool/pool_test.go b/pool/pool_test.go index 8a5aedc..316c6d0 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -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) +} + //--------------------------------- diff --git a/pool/strategy/persistent/nodeHelper_test.go b/pool/strategy/persistent/nodeHelper_test.go index f79c0dc..358b8b0 100644 --- a/pool/strategy/persistent/nodeHelper_test.go +++ b/pool/strategy/persistent/nodeHelper_test.go @@ -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) } @@ -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 { @@ -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) } diff --git a/pool/strategy/persistent/strategy_test.go b/pool/strategy/persistent/strategy_test.go index 62863e0..b70225d 100644 --- a/pool/strategy/persistent/strategy_test.go +++ b/pool/strategy/persistent/strategy_test.go @@ -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) diff --git a/storage/tests/mysql_test.go b/storage/mysql/mysql_test.go similarity index 85% rename from storage/tests/mysql_test.go rename to storage/mysql/mysql_test.go index 3d322e2..dea9bc9 100644 --- a/storage/tests/mysql_test.go +++ b/storage/mysql/mysql_test.go @@ -1,4 +1,4 @@ -package tests +package mysql import ( "crypto/rand" @@ -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" @@ -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()) } @@ -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) } diff --git a/storage/tests/comon_test.go b/storage/tests/comon.go similarity index 85% rename from storage/tests/comon_test.go rename to storage/tests/comon.go index 4396298..9c60689 100644 --- a/storage/tests/comon_test.go +++ b/storage/tests/comon.go @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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()