fixed linking error, almost ended integration tests

14-integration-tests
plazmoid 3 years ago
parent 8cccc82fc2
commit 5248ae7ac4
  1. 9
      .cargo/config.toml
  2. 8
      .gitignore
  3. 15
      Makefile
  4. 3
      bin/u_server/Dockerfile
  5. 2
      integration/.env
  6. 37
      integration/docker-compose.yml
  7. 20
      integration/docker.py
  8. 14
      integration/docker_compose.py
  9. 4
      integration/images/tests_runner.Dockerfile
  10. 0
      integration/images/u_agent.Dockerfile
  11. 3
      integration/images/u_db.Dockerfile
  12. 3
      integration/images/u_server.Dockerfile
  13. 5
      integration/integration_tests.py
  14. 4
      integration/integration_tests.sh
  15. 3
      integration/tests_runner.Dockerfile
  16. 2
      scripts/cargo_musl.sh

@ -1,9 +0,0 @@
[build]
target = "x86_64-unknown-linux-musl"
[target.x86_64-unknown-linux-musl]
rustflags = [
"-Ctarget-feature=+crt-static",
"-Clink-args=-Istatic/include",
"-L", "static/lib",
]

8
.gitignore vendored

@ -1,4 +1,6 @@
/target target/
**/*.rs.bk **/*.rs.bk
/.idea .idea/
/data data/
static/
**/*.pyc

@ -0,0 +1,15 @@
.PHONY: build run clean
CARGO=./scripts/cargo_musl.sh
clean:
${CARGO} clean
build:
cd muslrust
docker build -t unki/musllibs ./muslrust
cd -
${CARGO} build $@
run: build
${CARGO} run

@ -1,3 +0,0 @@
FROM centos:7
CMD yum update

@ -1,2 +1,2 @@
DATABASE_URL=postgres://postgres:12348756@u_db/u_db
PG_PASSWORD=12348756 PG_PASSWORD=12348756
DATABASE_URL=postgres://postgres:${PG_PASSWORD}@u_db/u_db

@ -11,26 +11,39 @@ services:
- u_net - u_net
volumes: volumes:
- ../target/x86_64-unknown-linux-musl/release/u_server:/u_server - ../target/x86_64-unknown-linux-musl/release/u_server:/u_server
- ./.env:/.env - ../:/unki/
command: /u_server working_dir: /unki
command: bash -c "diesel setup && diesel migration run && /u_server"
depends_on: depends_on:
u_db: u_db:
condition: service_started condition: service_healthy
expose: expose:
- '63714' - '63714'
environment: environment:
RUST_LOG: warp RUST_LOG: warp
env_file:
- .env
healthcheck:
test: /bin/ss -tlpn | grep 63714
interval: 5s
timeout: 2s
retries: 2
u_db: u_db:
image: postgres:13.3 image: unki/u_db
networks: networks:
- u_net - u_net
volumes: #volumes:
- ../data:/var/lib/postgresql/data # - ../data:/var/lib/postgresql/data
expose: expose:
- '5432' - '5432'
environment: environment:
- POSTGRES_PASSWORD=${PG_PASSWORD} - POSTGRES_PASSWORD=${PG_PASSWORD}
healthcheck:
test: /bin/ss -tlpn | grep 5432
interval: 5s
timeout: 2s
retries: 2
u_agent_1: u_agent_1:
image: unki/u_agent image: unki/u_agent
@ -41,7 +54,7 @@ services:
command: /u_agent u_server command: /u_agent u_server
depends_on: depends_on:
u_server: u_server:
condition: service_started condition: service_healthy
u_agent_2: u_agent_2:
image: unki/u_agent image: unki/u_agent
@ -52,7 +65,7 @@ services:
command: /u_agent u_server command: /u_agent u_server
depends_on: depends_on:
u_server: u_server:
condition: service_started condition: service_healthy
tests_runner: tests_runner:
image: unki/tests_runner image: unki/tests_runner
@ -60,6 +73,12 @@ services:
- u_net - u_net
volumes: volumes:
- ../:/unki/ - ../:/unki/
working_dir:
/unki
depends_on: depends_on:
u_server: u_agent_1:
condition: service_started condition: service_started
u_agent_2:
condition: service_started
u_server:
condition: service_healthy

@ -1,15 +1,23 @@
import subprocess import subprocess
from utils import * from utils import *
BASE_IMAGE_DIR = 'images'
DOCKERFILES = { DOCKERFILES = {
'u_agent': { 'u_agent': {
'ctx': '../bin/u_agent', 'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'u_agent'
}, },
'u_server': { 'u_server': {
'ctx': '../bin/u_server' 'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'u_server'
},
'u_db': {
'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'u_db'
}, },
'tests_runner': { 'tests_runner': {
'ctx': './', 'ctx': BASE_IMAGE_DIR,
'dockerfile_prefix': 'tests_runner' 'dockerfile_prefix': 'tests_runner'
}, },
} }
@ -18,10 +26,8 @@ DOCKERFILES = {
def docker(args): def docker(args):
try: try:
cmd = ['docker'] + args cmd = ['docker'] + args
#log(f'Running docker cmd: {cmd}') log(f'Running docker command: {cmd}')
return subprocess.check_output( return subprocess.check_output(cmd)
cmd
)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
err(str(e)) err(str(e))
raise raise

@ -1,4 +1,5 @@
import subprocess import subprocess
import shlex
from utils import * from utils import *
from docker import docker, check_state, print_errors from docker import docker, check_state, print_errors
@ -13,7 +14,9 @@ class Compose:
] ]
def __init__(self): def __init__(self):
self.cmd_container = 'tests_runner' self.container_tpl = 'integration_%s_1'
self.cmd_container = self.container_tpl % 'tests_runner'
self.ALL_CONTAINERS = [self.container_tpl % c for c in self.ALL_CONTAINERS]
def _call(self, *args): def _call(self, *args):
subprocess.check_call([ subprocess.check_call([
@ -24,7 +27,7 @@ class Compose:
def up(self): def up(self):
log('Instanciating cluster') log('Instanciating cluster')
self._call('up') self._call('up', '-d')
log('Ok') log('Ok')
def down(self): def down(self):
@ -39,13 +42,14 @@ class Compose:
def run(self, cmd): def run(self, cmd):
container = self.cmd_container container = self.cmd_container
if isinstance(cmd, str):
cmd = shlex.split(cmd)
log(f'Running command "{cmd}" in container {container}') log(f'Running command "{cmd}" in container {container}')
docker([ docker([
'exec', 'exec',
'-i', '-i',
f"'{container}'", container
f"'{cmd}'" ] + cmd)
])
log('Ok') log('Ok')
def is_alive(self): def is_alive(self):

@ -0,0 +1,4 @@
FROM rust:1.53
RUN rustup target add x86_64-unknown-linux-musl
CMD ["sleep", "3600"]

@ -0,0 +1,3 @@
FROM postgres:13.3
RUN apt update && apt -y upgrade && apt install -y iproute2

@ -0,0 +1,3 @@
FROM rust:1.53
RUN cargo install diesel_cli --no-default-features --features postgres

@ -15,9 +15,11 @@ def abort_handler(s, _):
def run_tests(): def run_tests():
force_rebuild = '--rebuild' in sys.argv
preserve_containers = '--preserve' in sys.argv
for s in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP): for s in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):
signal.signal(s, abort_handler) signal.signal(s, abort_handler)
rebuild_images_if_needed() rebuild_images_if_needed(force_rebuild)
try: try:
cluster.up() cluster.up()
cluster.is_alive() cluster.is_alive()
@ -26,6 +28,7 @@ def run_tests():
err(e) err(e)
sys.exit(1) sys.exit(1)
finally: finally:
if not preserve_containers:
cluster.down() cluster.down()

@ -1,5 +1,3 @@
#!/bin/bash #!/bin/bash
set -e set -e
CARGO=cargo python integration_tests.py $@
$CARGO build --release --target x86_64-unknown-linux-musl
python integration_tests.py

@ -1,3 +0,0 @@
FROM rust:1.53
CMD rustup target add x86_64-unknown-linux-musl

@ -6,6 +6,6 @@ docker run \
-v cargo-cache:/root/.cargo/registry \ -v cargo-cache:/root/.cargo/registry \
-w /volume \ -w /volume \
-it \ -it \
test/musllibs \ unki/musllibs \
cargo $@ cargo $@

Loading…
Cancel
Save