Skip to content

Tests/multi deployment #89

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

Merged
merged 8 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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: 0 additions & 1 deletion pkg/apis/storage/v1alpha/local_storage_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ package v1alpha
import (
"testing"

//"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

Expand Down
98 changes: 86 additions & 12 deletions tests/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ package tests

import (
"context"
"fmt"
"testing"

"github.com/dchest/uniuri"
"github.com/stretchr/testify/assert"

driver "github.com/arangodb/go-driver"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
kubeArangoClient "github.com/arangodb/kube-arangodb/pkg/client"
Expand Down Expand Up @@ -77,27 +81,97 @@ func deploymentSubTest(t *testing.T, mode api.DeploymentMode, engine api.Storage
deploymentTemplate.Spec.SetDefaults(deploymentTemplate.GetName()) // this must be last

// Create deployment
deployment, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate)
if err != nil {
t.Fatalf("Create deployment failed: %v", err)
}
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate)
assert.NoError(t, err, fmt.Sprintf("Create deployment failed: %v", err))

// Wait for deployment to be ready
deployment, err = waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
if err != nil {
t.Fatalf("Deployment not running in time: %v", err)
}
deployment, err := waitUntilDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace, deploymentIsReady())
assert.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err))

// Create a database client
ctx := context.Background()
DBClient := mustNewArangodDatabaseClient(ctx, k8sClient, deployment, t)

if err := waitUntilArangoDeploymentHealthy(deployment, DBClient, k8sClient, ""); err != nil {
t.Fatalf("Deployment not healthy in time: %v", err)
}
assert.NoError(t, waitUntilArangoDeploymentHealthy(deployment, DBClient, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))

// Cleanup
removeDeployment(deploymentClient, deploymentTemplate.GetName(), k8sNameSpace)

return nil
}

// test setup containing multiple deployments
func TestMultiDeployment1(t *testing.T) {
longOrSkip(t)

k8sNameSpace := getNamespace(t)
k8sClient := mustNewKubeClient(t)
deploymentClient := kubeArangoClient.MustNewInCluster()

// Prepare deployment config
deploymentTemplate1 := newDeployment("test-multidep1-1-" + uniuri.NewLen(4))
deploymentTemplate1.Spec.Mode = api.NewMode(api.DeploymentModeCluster)
deploymentTemplate1.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineRocksDB)
deploymentTemplate1.Spec.TLS = api.TLSSpec{} // should auto-generate cert
deploymentTemplate1.Spec.SetDefaults(deploymentTemplate1.GetName()) // this must be last

deploymentTemplate2 := newDeployment("test-multidep1-2-" + uniuri.NewLen(4))
deploymentTemplate2.Spec.Mode = api.NewMode(api.DeploymentModeSingle)
deploymentTemplate2.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineMMFiles)
deploymentTemplate2.Spec.TLS = api.TLSSpec{} // should auto-generate cert
deploymentTemplate2.Spec.SetDefaults(deploymentTemplate2.GetName()) // this must be last

// Create deployment
_, err := deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate1)
assert.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err))

_, err = deploymentClient.DatabaseV1alpha().ArangoDeployments(k8sNameSpace).Create(deploymentTemplate2)
assert.NoError(t, err, fmt.Sprintf("Deployment creation failed: %v", err))

// Wait for deployment to be ready
Copy link
Contributor

Choose a reason for hiding this comment

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

deployment -> deployments

deployment1, err := waitUntilDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace, deploymentIsReady())
assert.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err))

deployment2, err := waitUntilDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace, deploymentIsReady())
assert.NoError(t, err, fmt.Sprintf("Deployment not running in time: %v", err))

// Create a database client
Copy link
Contributor

Choose a reason for hiding this comment

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

client -> clients

ctx := context.Background()
DBClient1 := mustNewArangodDatabaseClient(ctx, k8sClient, deployment1, t)
assert.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))
DBClient2 := mustNewArangodDatabaseClient(ctx, k8sClient, deployment2, t)
assert.NoError(t, waitUntilArangoDeploymentHealthy(deployment1, DBClient1, k8sClient, ""), fmt.Sprintf("Deployment not healthy in time: %v", err))

db1, err := DBClient1.Database(ctx, "_system")
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment here to explain what the intent of line 144 - 152 is

assert.NoError(t, err, "failed to get database")
_, err = db1.CreateCollection(ctx, "col1", nil)
assert.NoError(t, err, "failed to create collection")

db2, err := DBClient2.Database(ctx, "_system")
assert.NoError(t, err, "failed to get database")
_, err = db2.CreateCollection(ctx, "col2", nil)
assert.NoError(t, err, "failed to create collection")

collections1, err := db1.Collections(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is where the "real test" starts, please add a comment explaining what is being checked

assert.NoError(t, err, "failed to get collections")
collections2, err := db2.Collections(ctx)
assert.NoError(t, err, "failed to get collections")

assert.True(t, containsCollection(collections1, "col1"), "collection missing")
assert.True(t, containsCollection(collections2, "col2"), "collection missing")
assert.False(t, containsCollection(collections1, "col2"), "collection must not be in this deployment")
assert.False(t, containsCollection(collections2, "col1"), "collection must not be in this deployment")

Copy link
Contributor

Choose a reason for hiding this comment

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

To make sure that we can talk to individual deployments, I'll like to see an additional test here.

  • Create a collection in deployment 1 (named col1)
  • Create a collection in deployment 2 (named col2)
  • Check that deployment 1 has a collection named col1 but not col2
  • Check that deployment 2 has a collection named col2 but not col1

// Cleanup
removeDeployment(deploymentClient, deploymentTemplate1.GetName(), k8sNameSpace)
removeDeployment(deploymentClient, deploymentTemplate2.GetName(), k8sNameSpace)

}

func containsCollection(colls []driver.Collection, name string) bool {
for _, col := range colls {
if name == col.Name() {
return true
}
}
return false
}