Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various test improvements #167

Merged
merged 2 commits into from
Jun 8, 2018
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
2 changes: 2 additions & 0 deletions scripts/kube_create_storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ if [ "${REQUIRE_LOCAL_STORAGE}" = "1" ]; then
else
echo "No local storage needed for this cluster"
fi
echo "Found $(kubectl get pv | wc -l) PersistentVolumes"
echo "Found $(kubectl get pv | grep Available | wc -l) available PersistentVolumes"
17 changes: 4 additions & 13 deletions tests/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"time"

"github.com/dchest/uniuri"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file you switch from "assert" to "require", in all the others not. Why is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the cases where require is used, other tests follow it.
I don't want to run these following tests when the requirement has failed


driver "github.com/arangodb/go-driver"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
Expand Down Expand Up @@ -71,10 +71,7 @@ func TestCursorSingle(t *testing.T) {
}

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingle, role)
require.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingle))

// Run cursor tests
runCursorTests(t, client)
Expand Down Expand Up @@ -118,10 +115,7 @@ func TestCursorActiveFailover(t *testing.T) {
}

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingleActive, role)
require.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingleActive))

// Run cursor tests
runCursorTests(t, client)
Expand Down Expand Up @@ -165,10 +159,7 @@ func TestCursorCluster(t *testing.T) {
}

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
require.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))

// Run cursor tests
runCursorTests(t, client)
Expand Down
20 changes: 4 additions & 16 deletions tests/service_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ func TestServiceAccountSingle(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.Single, saName, t)

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingle, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingle))
}

// TestServiceAccountActiveFailover tests the creating of a ActiveFailover server deployment
Expand Down Expand Up @@ -137,10 +134,7 @@ func TestServiceAccountActiveFailover(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.Agents, saName, t)

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingleActive, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingleActive))
}

// TestServiceAccountCluster tests the creating of a cluster deployment
Expand Down Expand Up @@ -192,10 +186,7 @@ func TestServiceAccountCluster(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.DBServers, saName, t)

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
}

// TestServiceAccountClusterWithSync tests the creating of a cluster deployment
Expand Down Expand Up @@ -262,10 +253,7 @@ func TestServiceAccountClusterWithSync(t *testing.T) {
checkMembersUsingServiceAccount(kubecli, ns, apiObject.Status.Members.SyncWorkers, saName, t)

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
}

// mustCreateServiceAccount creates an empty service account with random name and returns
Expand Down
20 changes: 4 additions & 16 deletions tests/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ func TestSimpleSingle(t *testing.T) {
}

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingle, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingle))
}

// TestSimpleActiveFailover tests the creating of a ActiveFailover server deployment
Expand Down Expand Up @@ -111,10 +108,7 @@ func TestSimpleActiveFailover(t *testing.T) {
}

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleSingleActive, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleSingleActive))
}

// TestSimpleCluster tests the creating of a cluster deployment
Expand Down Expand Up @@ -152,10 +146,7 @@ func TestSimpleCluster(t *testing.T) {
}

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
}

// TestSimpleClusterWithSync tests the creating of a cluster deployment
Expand Down Expand Up @@ -204,8 +195,5 @@ func TestSimpleClusterWithSync(t *testing.T) {
}

// Check server role
assert.NoError(t, client.SynchronizeEndpoints(ctx))
role, err := client.ServerRole(ctx)
assert.NoError(t, err)
assert.Equal(t, driver.ServerRoleCoordinator, role)
assert.NoError(t, testServerRole(ctx, client, driver.ServerRoleCoordinator))
}
25 changes: 24 additions & 1 deletion tests/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,30 @@ func waitUntilArangoDeploymentHealthy(deployment *api.ArangoDeployment, DBClient
}
}
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
}