1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

Various test improvements

This commit is contained in:
Ewout Prangsma 2018-06-08 09:37:20 +02:00
parent d12ad72fdb
commit 32b3a738eb
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698
5 changed files with 38 additions and 46 deletions

View file

@ -20,3 +20,5 @@ if [ "${REQUIRE_LOCAL_STORAGE}" = "1" ]; then
else else
echo "No local storage needed for this cluster" echo "No local storage needed for this cluster"
fi fi
echo "Found $(kubectl get pv | wc -l) PersistentVolumes"
echo "Found $(kubectl get pv | grep Available | wc -l) available PersistentVolumes"

View file

@ -29,7 +29,7 @@ import (
"time" "time"
"github.com/dchest/uniuri" "github.com/dchest/uniuri"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/require"
driver "github.com/arangodb/go-driver" driver "github.com/arangodb/go-driver"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
@ -71,10 +71,7 @@ func TestCursorSingle(t *testing.T) {
} }
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) require.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingle))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingle, role)
// Run cursor tests // Run cursor tests
runCursorTests(t, client) runCursorTests(t, client)
@ -118,10 +115,7 @@ func TestCursorActiveFailover(t *testing.T) {
} }
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) require.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingleActive))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingleActive, role)
// Run cursor tests // Run cursor tests
runCursorTests(t, client) runCursorTests(t, client)
@ -165,10 +159,7 @@ func TestCursorCluster(t *testing.T) {
} }
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) require.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
// Run cursor tests // Run cursor tests
runCursorTests(t, client) runCursorTests(t, client)

View file

@ -84,10 +84,7 @@ func TestServiceAccountSingle(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.Single, saName, t) checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.Single, saName, t)
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingle))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingle, role)
} }
// TestServiceAccountActiveFailover tests the creating of a ActiveFailover server deployment // TestServiceAccountActiveFailover tests the creating of a ActiveFailover server deployment
@ -137,10 +134,7 @@ func TestServiceAccountActiveFailover(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.Agents, saName, t) checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.Agents, saName, t)
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingleActive))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingleActive, role)
} }
// TestServiceAccountCluster tests the creating of a cluster deployment // TestServiceAccountCluster tests the creating of a cluster deployment
@ -192,10 +186,7 @@ func TestServiceAccountCluster(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.DBServers, saName, t) checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.DBServers, saName, t)
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
} }
// TestServiceAccountClusterWithSync tests the creating of a cluster deployment // TestServiceAccountClusterWithSync tests the creating of a cluster deployment
@ -262,10 +253,7 @@ func TestServiceAccountClusterWithSync(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.SyncWorkers, saName, t) checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.SyncWorkers, saName, t)
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
} }
// mustCreateServiceAccount creates an empty service account with random name and returns // mustCreateServiceAccount creates an empty service account with random name and returns

View file

@ -70,10 +70,7 @@ func TestSimpleSingle(t *testing.T) {
} }
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingle))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingle, role)
} }
// TestSimpleActiveFailover tests the creating of a ActiveFailover server deployment // TestSimpleActiveFailover tests the creating of a ActiveFailover server deployment
@ -111,10 +108,7 @@ func TestSimpleActiveFailover(t *testing.T) {
} }
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingleActive))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingleActive, role)
} }
// TestSimpleCluster tests the creating of a cluster deployment // TestSimpleCluster tests the creating of a cluster deployment
@ -152,10 +146,7 @@ func TestSimpleCluster(t *testing.T) {
} }
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
} }
// TestSimpleClusterWithSync tests the creating of a cluster deployment // TestSimpleClusterWithSync tests the creating of a cluster deployment
@ -204,8 +195,5 @@ func TestSimpleClusterWithSync(t *testing.T) {
} }
// Check server role // Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx)) assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
} }

View file

@ -506,7 +506,30 @@ func waitUntilArangoDeploymentHealthy(deployment *api.ArangoDeployment, DBClient
} }
} }
default: default:
return maskAny(fmt.Errorf("DeploymentMode %s is not supported!", mode)) return maskAny(fmt.Errorf("DeploymentMode %s is not supported", mode))
}
return nil
}
// testServerRole performs a synchronize endpoints and then requests the server role.
// On success, the role is compared with the given expected role.
// When the requests fail or the role is not equal to the expected role, an error is returned.
func testServerRole(ctx context.Context, client driver.Client, expectedRole driver.ServerRole) error {
op := func(ctx context.Context) error {
if err := client.SynchronizeEndpoints(ctx); err != nil {
return maskAny(err)
}
role, err := client.ServerRole(ctx)
if err != nil {
return maskAny(err)
}
if role != expectedRole {
return retry.Permanent(fmt.Errorf("Unexpected server role: Expected '%s', got '%s'", expectedRole, role))
}
return nil
}
if err := retry.RetryWithContext(ctx, op, time.Second*20); err != nil {
return maskAny(err)
} }
return nil return nil
} }