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

Parallelize Drone testing #233

Merged
merged 4 commits into from
Nov 1, 2023
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
88 changes: 81 additions & 7 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,98 @@ steps:
- name: docker
path: /var/run/docker.sock

- name: test
image: rancher/dapper:v0.6.0
- name: test-image
image: rancher/dapper:v0.5.0
commands:
- docker build -t kine:test-${DRONE_COMMIT} -f Dockerfile.test .
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT}
environment:
ARCH: "${DRONE_STAGE_ARCH}"
DOCKER_BUILDKIT: "1"
volumes:
- name: docker
path: /var/run/docker.sock
when:
instance:
- drone-pr.k3s.io

- name: test-sqlite
image: rancher/dapper:v0.5.0
depends_on:
- build
- test-image
commands:
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT} "./scripts/test sqlite"
volumes:
- name: docker
path: /var/run/docker.sock

- name: test-mysql
image: rancher/dapper:v0.5.0
depends_on:
- build
- test-image
commands:
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT} "./scripts/test mysql"
volumes:
- name: docker
path: /var/run/docker.sock

- name: test-postgres
image: rancher/dapper:v0.5.0
depends_on:
- build
- test-image
commands:
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT} "./scripts/test postgres"
volumes:
- name: docker
path: /var/run/docker.sock

- name: test-cockroachdb
image: rancher/dapper:v0.5.0
depends_on:
- build
- test-image
commands:
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT} "./scripts/test cockroachdb"
volumes:
- name: docker
path: /var/run/docker.sock

- name: test-nats
image: rancher/dapper:v0.5.0
depends_on:
- build
- test-image
commands:
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT} "./scripts/test nats"
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT} "./scripts/test nats-embedded"
- >
docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME
-v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache
--privileged kine:test-${DRONE_COMMIT} "./scripts/test nats-socket"
volumes:
- name: docker
path: /var/run/docker.sock


- name: github_binary_release
image: plugins/github-release
settings:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Unit Test
on:
push:
branches: [main, master]

pull_request:
branches: [main, master]

permissions:
contents: read

jobs:
unit-test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Go Unit Tests
run: go test -cover -tags=test ./...
4 changes: 2 additions & 2 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ WORKDIR ${KINE_SOURCE}

COPY . ${KINE_SOURCE}

ENTRYPOINT ["./scripts/entry"]
CMD ["test"]
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["./scripts/test"]
2 changes: 1 addition & 1 deletion hack/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main(type, *args, **kwargs):

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--type', '-t', type=str, required=False, default='core.ConfigMap')
parser.add_argument('--type', '-t', type=str, required=False, default='configmaps')
parser.add_argument('--log-level', '-l', type=str, required=False, default='INFO')
parser.add_argument('--backend-name', '-b', type=str, required=False, default='etcd')
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion hack/loadmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def list_configmaps():

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--rounds', '-r', type=int, required=False, default=5000)
parser.add_argument('--rounds', '-r', type=int, required=False, default=4000)
parser.add_argument('--log-level', '-l', type=str, required=False, default='INFO')
args = parser.parse_args()

Expand Down
11 changes: 8 additions & 3 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ cd $(dirname $0)/..

. ./scripts/test-helpers

#echo Running go unit tests
go test -cover -tags=test ./...

# ---

docker ps

# ---

# Selectively run tests
if [ -n "$1" ]; then
. ./scripts/test-run-"$1"
echo "Did test-run-$1 $?"
exit 0
fi


. ./scripts/test-run-sqlite
echo "Did test-run-sqlite $?"

Expand Down
17 changes: 15 additions & 2 deletions scripts/test-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ export -f inc-count

# ---

find-free-port() {
activePorts=$(docker ps -a --format "{{.Names}}\t{{.Ports}}" | awk -F ' ' '{if($2){print $2}}')
for port in $(shuf -i 5000-8000 -n 20); do
if ! echo "$activePorts" | grep -q "$port"; then
echo "$port"
return 0
fi
done
}
export -f find-free-port
# ---

has-function() {
[[ ! -z "$1" && $(type -t $1) == "function" ]]
} 2> /dev/null
Expand Down Expand Up @@ -196,13 +208,14 @@ provision-server() {
local count=$(inc-count servers)
local testID=$(basename $TEST_DIR)
local name=$(echo "k3s-server-$count-$testID" | tee $TEST_DIR/servers/$count/metadata/name)
local testPort=$(find-free-port)

run-function server-pre-hook $count

docker container run \
-d --name $name \
--privileged \
-p 6443:6443 \
-p $testPort:6443 \
-e K3S_DEBUG=true \
-e K3S_DATASTORE_ENDPOINT=$K3S_DATASTORE_ENDPOINT \
${K3S_IMAGE:-docker.io/rancher/k3s:v1.26.9-k3s1} server \
Expand All @@ -213,7 +226,7 @@ provision-server() {
local port=$(docker container inspect --format '{{range $k, $v := .NetworkSettings.Ports}}{{printf "%s\n" $k}}{{end}}' $name | head -n 1 | cut -d/ -f1 | tee $TEST_DIR/servers/$count/metadata/port)
local url=$(echo "https://$ip:$port" | tee $TEST_DIR/servers/$count/metadata/url)

echo "Started $name @ $url"
echo "Started $name @ $url (hp:$testPort)"
run-function server-post-hook $count
}
export -f provision-server
Expand Down
3 changes: 1 addition & 2 deletions scripts/test-run-postgres
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ VERSION_LIST="\
postgres 15.4
postgres 14.9
postgres 13.12
postgres 12.16
postgres 11.21-alpine" # A generic 11.21 image is not available
postgres 12.16"

while read ENGINE VERSION; do
LABEL=$ENGINE-$VERSION DB_PASSWORD_ENV=POSTGRES_PASSWORD DB_IMAGE=docker.io/library/$ENGINE:$VERSION run-test
Expand Down