Skip to content

Commit

Permalink
test: add pre-building of slow projects
Browse files Browse the repository at this point in the history
Added pre-building of project_with_cartridge and default_project before integration tests.
Result: ~25-50% faster testing.

Closes #390
  • Loading branch information
better0fdead committed Jul 14, 2022
1 parent e8f3dee commit 714d564
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 90 deletions.
17 changes: 14 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// +build mage
//go:build mage

package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -161,9 +162,19 @@ func Unit() error {
// Run integration tests
func Integration() error {
mg.Deps(GenerateGoCode)

build_projects_path, err := ioutil.TempDir("", "cartridge_cli_test_temp_")
defer os.RemoveAll(build_projects_path)
fmt.Println("Running integration tests...")
return sh.RunV(py3Exe, "-m", "pytest", "test/integration")
os.Setenv("CC_TEST_PREBUILT_PROJECTS", build_projects_path)
err = sh.RunV(py3Exe, "-m", "pytest", "test/make_preparations/test_build_projects.py")
if err != nil {
return err
}
err = sh.RunV(py3Exe, "-m", "pytest", "test/integration")
if err != nil {
return err
}
return err
}

// Run examples tests
Expand Down
15 changes: 3 additions & 12 deletions test/integration/admin/test_default.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import subprocess

import pytest
from project import patch_cartridge_proc_titile
from project import copy_project, patch_cartridge_proc_titile
from utils import (get_admin_connection_params, get_log_lines,
run_command_and_get_output, start_instances)


@pytest.fixture(scope="function")
def default_admin_running_instances(cartridge_cmd, start_stop_cli, project_with_cartridge):
def default_admin_running_instances(start_stop_cli, project_with_cartridge):
project = project_with_cartridge

# build project
cmd = [
cartridge_cmd,
"build",
]
process = subprocess.run(cmd, cwd=project.path)
assert process.returncode == 0, "Error during building the project"
copy_project("project_with_cartridge", project)

# don't change process title
patch_cartridge_proc_titile(project)
Expand Down
48 changes: 9 additions & 39 deletions test/integration/cli/test_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import subprocess

import pytest
from project import remove_project_file
from project import copy_project, remove_project_file
from utils import run_command_and_get_output


Expand All @@ -14,17 +14,9 @@ def test_version_command(cartridge_cmd, version_cmd):


@pytest.mark.parametrize('version_cmd', ['version', '-v', '--version'])
def test_version_command_with_project(project_with_cartridge, version_cmd, cartridge_cmd, tmpdir):
def test_version_command_with_project(project_with_cartridge, version_cmd, cartridge_cmd):
project = project_with_cartridge

cmd = [
cartridge_cmd,
"build",
project.path
]

process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0
copy_project("project_with_cartridge", project)

cmd = [
cartridge_cmd, version_cmd,
Expand All @@ -40,17 +32,9 @@ def test_version_command_with_project(project_with_cartridge, version_cmd, cartr


@pytest.mark.parametrize('version_cmd', ['version', '-v', '--version'])
def test_version_command_with_rocks(project_with_cartridge, version_cmd, cartridge_cmd, tmpdir):
def test_version_command_with_rocks(project_with_cartridge, version_cmd, cartridge_cmd):
project = project_with_cartridge

cmd = [
cartridge_cmd,
"build",
project.path
]

process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0
copy_project("project_with_cartridge", project)

cmd = [
cartridge_cmd,
Expand Down Expand Up @@ -113,17 +97,9 @@ def test_version_command_invalid_path(cartridge_cmd, version_cmd):


@pytest.mark.parametrize('version_cmd', ['version', '-v', '--version'])
def test_duplicate_rocks(project_with_cartridge, cartridge_cmd, version_cmd, tmpdir):
def test_duplicate_rocks(project_with_cartridge, cartridge_cmd, version_cmd):
project = project_with_cartridge

cmd = [
cartridge_cmd,
"build",
project.path
]

process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0
copy_project("project_with_cartridge", project)

# Cartridge already has graphql dependency
cmd = [
Expand All @@ -147,15 +123,9 @@ def test_duplicate_rocks(project_with_cartridge, cartridge_cmd, version_cmd, tmp


@pytest.mark.parametrize('version_cmd', ['version', '-v', '--version'])
def test_duplicate_cartridge_no_rocks_flag(project_with_cartridge, cartridge_cmd, version_cmd, tmpdir):
def test_duplicate_cartridge_no_rocks_flag(project_with_cartridge, cartridge_cmd, version_cmd):
project = project_with_cartridge

cmd = [
cartridge_cmd, "build", project.path
]

process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0
copy_project("project_with_cartridge", project)

# Install one more Cartridge
cmd = [
Expand Down
9 changes: 4 additions & 5 deletions test/integration/create/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess

import pytest
from project import Project
from project import Project, copy_project
from utils import recursive_listdir, run_command_and_get_output


Expand All @@ -13,11 +13,10 @@ def default_project(cartridge_cmd, module_tmpdir):
return project


def test_project(cartridge_cmd, default_project):
def test_project(default_project):
project = default_project

process = subprocess.run([cartridge_cmd, 'build'], cwd=project.path)
assert process.returncode == 0, "Error building project"
copy_project("default_project", project)

process = subprocess.run(['./deps.sh'], cwd=project.path)
assert process.returncode == 0, "Installing deps failed"
Expand All @@ -42,7 +41,7 @@ def test_project_recreation(cartridge_cmd, default_project):

rc, output = run_command_and_get_output(cmd)
assert rc == 1
assert "Application already exists in {}".format(project.path) in output
assert "Application already exists in {}".format(project.path[:-6]) in output

# check that project directory wasn't deleted
assert os.path.exists(project.path)
Expand Down
26 changes: 4 additions & 22 deletions test/integration/repair/test_repair_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
import requests
from project import (patch_cartridge_proc_titile,
from project import (copy_project, patch_cartridge_proc_titile,
patch_cartridge_returned_version)
from utils import (check_instances_running, check_instances_stopped,
create_replicaset, run_command_and_get_output,
Expand Down Expand Up @@ -102,13 +102,7 @@ def test_repair_reload_set_leader(cartridge_cmd, start_stop_cli, project_with_ca
project = project_with_cartridge
cli = start_stop_cli

cmd = [
cartridge_cmd,
"build",
project.path
]
process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0, "Error during building the project"
copy_project("project_with_cartridge", project)

# patch cartridge.cfg to don't change process title
patch_cartridge_proc_titile(project)
Expand Down Expand Up @@ -180,13 +174,7 @@ def test_repair_reload_remove_instance(cartridge_cmd, start_stop_cli, project_wi
project = project_with_cartridge
cli = start_stop_cli

cmd = [
cartridge_cmd,
"build",
project.path
]
process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0, "Error during building the project"
copy_project("project_with_cartridge", project)

# patch cartridge.cfg to don't change process title
patch_cartridge_proc_titile(project)
Expand Down Expand Up @@ -268,13 +256,7 @@ def test_repair_reload_set_uri(cartridge_cmd, start_stop_cli, project_with_cartr
project = project_with_cartridge
cli = start_stop_cli

cmd = [
cartridge_cmd,
"build",
project.path
]
process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0, "Error during building the project"
copy_project("project_with_cartridge", project)

# patch cartridge.cfg to don't change process title
patch_cartridge_proc_titile(project)
Expand Down
11 changes: 2 additions & 9 deletions test/integration/replicasets/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import subprocess

import yaml
from integration.replicasets.utils import get_list_from_log_lines
from project import patch_cartridge_proc_titile
from project import copy_project, patch_cartridge_proc_titile
from utils import (get_log_lines, get_replicasets, is_vshard_bootstrapped,
run_command_and_get_output, write_conf)

Expand Down Expand Up @@ -61,13 +60,7 @@ def test_default_application(cartridge_cmd, start_stop_cli, project_with_cartrid
cli = start_stop_cli
project = project_with_cartridge

# build project
cmd = [
cartridge_cmd,
"build",
]
process = subprocess.run(cmd, cwd=project.path)
assert process.returncode == 0, "Error during building the project"
copy_project("project_with_cartridge", project)

# don't change process title
patch_cartridge_proc_titile(project)
Expand Down
48 changes: 48 additions & 0 deletions test/make_preparations/test_build_projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import shutil
import subprocess

import pytest
from project import Project


@pytest.fixture(scope="module")
def default_project(cartridge_cmd, module_tmpdir):
project = Project(cartridge_cmd, 'default-project', module_tmpdir, 'cartridge')
return project


def test_make_project_with_cartridge(project_with_cartridge, cartridge_cmd, tmpdir):
project = project_with_cartridge
dir = os.getenv("CC_TEST_PREBUILT_PROJECTS")
if dir is None:
print("Directory for cartridge-cli integration tests prebuilt projects is not set.\n",
"Please set enviromental variable: CC_TEST_PREBUILT_PROJECTS")
assert dir is not None
path = dir + "/project_with_cartridge"

cmd = [
cartridge_cmd, "build", project.path
]

process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0
shutil.copytree(project.path, path)


def test_make_default_project(default_project, cartridge_cmd, tmpdir):
project = default_project
dir = os.getenv("CC_TEST_PREBUILT_PROJECTS")
if dir is None:
print("Directory for cartridge-cli integration tests prebuilt projects is not set.\n",
"Please set enviromental variable: CC_TEST_PREBUILT_PROJECTS")
assert dir is not None
path = dir + "/default_project"

cmd = [
cartridge_cmd, "build", project.path
]

process = subprocess.run(cmd, cwd=tmpdir)
assert process.returncode == 0
shutil.copytree(project.path, path)
6 changes: 6 additions & 0 deletions test/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,9 @@ def set_and_return_whoami_on_build(rockspec_path, project_name, version):
'''.format(project_name, version, who_am_i))

return who_am_i


def copy_project(project_name, project):
dir = os.getenv("CC_TEST_PREBUILT_PROJECTS")
shutil.copytree(dir + "/" + project_name, project.path + "/built")
project.path = project.path + "/built"

0 comments on commit 714d564

Please sign in to comment.