-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from arangodb/test/duration
Added duration test app
- Loading branch information
Showing
21 changed files
with
2,070 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM scratch | ||
|
||
ADD bin/arangodb_operator_duration_test /usr/bin/ | ||
|
||
ENTRYPOINT [ "/usr/bin/arangodb_operator_duration_test" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Kube-ArangoDB duration test | ||
|
||
This test is a simple application that keeps accessing the database with various requests. | ||
|
||
## Building | ||
|
||
In root of kube-arangodb repository, run: | ||
|
||
```bash | ||
make docker-duration-test | ||
``` | ||
|
||
## Running | ||
|
||
Start an ArangoDB `Cluster` deployment. | ||
|
||
Run: | ||
|
||
```bash | ||
kubectl run \ | ||
--image=${DOCKERNAMESPACE}/kube-arangodb-durationtest:dev \ | ||
--image-pull-policy=Always duration-test \ | ||
-- \ | ||
--cluster=https://<deployment-name>.<namespace>.svc:8529 \ | ||
--username=root | ||
``` | ||
|
||
To remove the test, run: | ||
|
||
```bash | ||
kubectl delete -n <namespace> deployment/duration-test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// | ||
// DISCLAIMER | ||
// | ||
// Copyright 2018 ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Author Ewout Prangsma | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"strings" | ||
"syscall" | ||
"time" | ||
|
||
driver "github.com/arangodb/go-driver" | ||
"github.com/arangodb/go-driver/http" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/arangodb/kube-arangodb/pkg/util/retry" | ||
) | ||
|
||
const ( | ||
defaultTestDuration = time.Hour * 24 * 7 // 7 days | ||
) | ||
|
||
var ( | ||
maskAny = errors.WithStack | ||
userName string | ||
password string | ||
clusterEndpoints string | ||
testDuration time.Duration | ||
) | ||
|
||
func init() { | ||
flag.StringVar(&userName, "username", "", "Authenticating username") | ||
flag.StringVar(&password, "password", "", "Authenticating password") | ||
flag.StringVar(&clusterEndpoints, "cluster", "", "Endpoints for database cluster") | ||
flag.DurationVar(&testDuration, "duration", defaultTestDuration, "Duration of the test") | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
// Create clients & wait for cluster available | ||
client, err := createClusterClient(clusterEndpoints, userName, password) | ||
if err != nil { | ||
log.Fatalf("Failed to create cluster client: %#v\n", err) | ||
} | ||
if err := waitUntilClusterUp(client); err != nil { | ||
log.Fatalf("Failed to reach cluster: %#v\n", err) | ||
} | ||
|
||
// Start running tests | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
sigChannel := make(chan os.Signal) | ||
signal.Notify(sigChannel, os.Interrupt, syscall.SIGTERM) | ||
go handleSignal(sigChannel, cancel) | ||
runTestLoop(ctx, client, testDuration) | ||
} | ||
|
||
// createClusterClient creates a configuration, connection and client for | ||
// one of the two ArangoDB clusters in the test. It uses the go-driver. | ||
// It needs a list of endpoints. | ||
func createClusterClient(endpoints string, user string, password string) (driver.Client, error) { | ||
// This will always use HTTP, and user and password authentication | ||
config := http.ConnectionConfig{ | ||
Endpoints: strings.Split(endpoints, ","), | ||
TLSConfig: &tls.Config{InsecureSkipVerify: true}, | ||
} | ||
connection, err := http.NewConnection(config) | ||
if err != nil { | ||
return nil, maskAny(err) | ||
} | ||
clientCfg := driver.ClientConfig{ | ||
Connection: connection, | ||
Authentication: driver.BasicAuthentication(user, password), | ||
} | ||
client, err := driver.NewClient(clientCfg) | ||
if err != nil { | ||
return nil, maskAny(err) | ||
} | ||
return client, nil | ||
} | ||
|
||
func waitUntilClusterUp(c driver.Client) error { | ||
op := func() error { | ||
ctx := context.Background() | ||
if _, err := c.Version(ctx); err != nil { | ||
return maskAny(err) | ||
} | ||
return nil | ||
} | ||
if err := retry.Retry(op, time.Minute); err != nil { | ||
return maskAny(err) | ||
} | ||
return nil | ||
} | ||
|
||
// handleSignal listens for termination signals and stops this process on termination. | ||
func handleSignal(sigChannel chan os.Signal, cancel context.CancelFunc) { | ||
signalCount := 0 | ||
for s := range sigChannel { | ||
signalCount++ | ||
fmt.Println("Received signal:", s) | ||
if signalCount > 1 { | ||
os.Exit(1) | ||
} | ||
cancel() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// DISCLAIMER | ||
// | ||
// Copyright 2018 ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Author Ewout Prangsma | ||
// | ||
|
||
package simple | ||
|
||
import "context" | ||
|
||
// isDocumentEqualTo reads an existing document and checks that it is equal to the given document. | ||
// Returns: (isEqual,currentRevision,error) | ||
func (t *simpleTest) isDocumentEqualTo(c *collection, key string, expected UserDocument) (bool, string, error) { | ||
ctx := context.Background() | ||
var result UserDocument | ||
t.log.Info().Msgf("Checking existing document '%s' from '%s'...", key, c.name) | ||
col, err := t.db.Collection(ctx, c.name) | ||
if err != nil { | ||
return false, "", maskAny(err) | ||
} | ||
m, err := col.ReadDocument(ctx, key, &result) | ||
if err != nil { | ||
// This is a failure | ||
t.log.Error().Msgf("Failed to read document '%s' from '%s': %v", key, c.name, err) | ||
return false, "", maskAny(err) | ||
} | ||
// Compare document against expected document | ||
if result.Equals(expected) { | ||
// Found an exact match | ||
return true, m.Rev, nil | ||
} | ||
t.log.Info().Msgf("Document '%s' in '%s' returned different values: got %q expected %q", key, c.name, result, expected) | ||
return false, m.Rev, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// DISCLAIMER | ||
// | ||
// Copyright 2018 ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Author Ewout Prangsma | ||
// | ||
|
||
package simple | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
var ( | ||
maskAny = errors.WithStack | ||
) |
Oops, something went wrong.