33set -ex
44
55domain_name=" "
6+ shard_index=" "
7+ shard_total=" "
68
79usage () {
8- echo " Usage: $0 -d <domain_name>"
10+ echo " Usage: $0 -d <domain_name> | -s <shard_index> -t <shard_total> "
911 exit 1
1012}
1113
12- while getopts " d:" opt; do
14+ setup_and_start_services () {
15+ node bin/prepare.js -f condo -r condo -c condo
16+
17+ export NEWS_ITEMS_SENDING_DELAY_SEC=2
18+ export NEWS_ITEM_SENDING_TTL_SEC=2
19+ export NODE_OPTIONS=" --max_old_space_size=4192"
20+ export WORKER_CONCURRENCY=100
21+ export DATABASE_POOL_MAX=10
22+
23+ node -e ' console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
24+
25+ # NOTE(pahaz): Keystone not in dev mode trying to check dist/admin folder
26+ mkdir -p ./apps/condo/dist/admin
27+
28+ yarn workspace @app/condo start 2>&1 > /app/test_logs/condo.dev.log &
29+
30+ node bin/wait-apps-apis.js -f condo
31+
32+ # check migrations
33+ yarn workspace @app/condo makemigrations --check & > /dev/null
34+
35+ source bin/validate-db-schema-ts-to-match-graphql-api.sh
36+
37+ yarn workspace @app/condo worker 2>&1 > /app/test_logs/condo.worker.log &
38+ sleep 3
39+
40+ # And check background processes!
41+ [[ $( jobs | wc -l | tr -d ' ' ) != ' 2' ]] && exit 2
42+ sleep 3
43+ }
44+
45+ stop_services () {
46+ # Note: we need to stop background worker! because packages tests use the same redis queue
47+ kill $( jobs -p) || echo ' background worker and dev server is already killed!'
48+ killall node || echo ' no node processes'
49+ }
50+
51+ while getopts " :d:s:t:" opt; do
1352 case $opt in
1453 d)
1554 domain_name=" $OPTARG "
1655 ;;
56+ s)
57+ shard_index=" $OPTARG "
58+ ;;
59+ t)
60+ shard_total=" $OPTARG "
61+ ;;
1762 \? )
1863 echo " Invalid option: -$OPTARG " >&2
1964 usage
@@ -25,62 +70,89 @@ while getopts "d:" opt; do
2570 esac
2671done
2772
28- if [ -z " $domain_name " ]; then
29- echo " -d is a required argument! "
73+ if [ -n " $domain_name " ] && { [ -n " $shard_index " ] || [ -n " $shard_total " ] ; } ; then
74+ echo " Use either legacy domain mode (-d) or shard mode (-s/-t), not both "
3075 usage
3176fi
3277
33- node bin/prepare.js -f condo -r condo -c condo
34-
35- export NEWS_ITEMS_SENDING_DELAY_SEC=2
36- export NEWS_ITEM_SENDING_TTL_SEC=2
37- export NODE_OPTIONS=" --max_old_space_size=4192"
38- export WORKER_CONCURRENCY=100
39- export DATABASE_POOL_MAX=10
40-
41- node -e ' console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
42-
43- # NOTE(pahaz): Keystone not in dev mode trying to check dist/admin folder
44- mkdir -p ./apps/condo/dist/admin
45-
46- yarn workspace @app/condo start 2>&1 > /app/test_logs/condo.dev.log &
78+ if [ -n " $domain_name " ]; then
79+ setup_and_start_services
80+
81+ if [ " $domain_name " != ' others' ]; then
82+ # TESTS
83+ yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=3 --forceExit --silent=false --verbose --bail --testPathPattern ' /domains/' $domain_name ' /schema/(.*)[.]test.js$' 2>&1 > ' /app/test_logs/condo.' $domain_name ' .tests.log'
84+ # SPECS
85+ if [ -n " $( find apps/condo/domains/$domain_name -name ' *spec.[j|t]s' 2> /dev/null) " ]; then
86+ yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=2 --forceExit --silent=false --verbose --bail --testPathPattern ' /domains/' $domain_name ' /(.*)[.]spec.[j|t]s$' 2>&1 > ' /app/test_logs/condo.' $domain_name ' .specs.log'
87+ else
88+ echo " Files matching (.*)[.]spec.[j|t]s in directory apps/condo/domains/$domain_name not found! Skipping..."
89+ fi
90+ else
91+ # TESTS
92+ yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=3 --forceExit --silent=false --verbose --bail --testPathPattern ' /schema/(.*)[.]test.js$' --testPathIgnorePatterns=' /domains/(organization|user|scope|property|acquiring|billing|miniapp|banking|ticket|meter|contact|resident|notification|common)/' 2>&1 > /app/test_logs/condo.others.tests.log
93+ yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=3 --forceExit --silent=false --verbose --bail --testPathPattern ' (.*)[.]test.js$' --testPathIgnorePatterns=' /schema/(.*)[.]test.js$' 2>&1 > /app/test_logs/condo.5.test.others.log
94+ # SPECS
95+ yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=2 --forceExit --silent=false --verbose --bail --testPathPattern ' (.*)[.]spec.[j|t]s$' --testPathIgnorePatterns=' /domains/(organization|user|scope|property|acquiring|billing|miniapp|banking|ticket|meter|contact|resident|notification|common)/' 2>&1 > /app/test_logs/condo.others.specs.log
96+ fi
4797
48- node bin/wait-apps-apis.js -f condo
98+ stop_services
4999
50- # check migrations
51- yarn workspace @app/condo makemigrations --check & > /dev/null
100+ if [ " $domain_name " = ' others' ]; then
101+ # TODO: INFRA-155 Remove it completely by rewriting a task tests or migrate to jest.setup or smth
102+ REDIS_URL=' [{"port":7001,"host":"127.0.0.1"},{"port":7002,"host":"127.0.0.1"},{"port":7003,"host":"127.0.0.1"}]' yarn workspace @open-condo/keystone test
103+ yarn workspace @app/condo lint-schema
104+ fi
52105
53- source bin/validate-db-schema-ts-to-match-graphql-api.sh
106+ exit 0
107+ fi
54108
55- yarn workspace @app/condo worker 2>&1 > /app/test_logs/condo.worker.log &
56- sleep 3
109+ if [ -z " $shard_index " ] || [ -z " $shard_total " ]; then
110+ echo " -s and -t are required arguments!"
111+ usage
112+ fi
57113
58- # And check background processes!
59- [[ $( jobs | wc -l | tr -d ' ' ) != ' 2' ]] && exit 2
60- sleep 3
114+ if ! [[ " $shard_index " =~ ^[0-9]+$ ]] || ! [[ " $shard_total " =~ ^[0-9]+$ ]]; then
115+ echo " -s and -t must be positive numbers"
116+ exit 1
117+ fi
61118
62- if [ $domain_name != " others" ]; then
63- # TESTS
64- yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=3 --forceExit --silent=false --verbose --bail --testPathPattern ' /domains/' $domain_name ' /schema/(.*)[.]test.js$' 2>&1 > ' /app/test_logs/condo.' $domain_name ' .tests.log'
65- # SPECS
66- if [ -n " $( find apps/condo/domains/$domain_name -name ' *spec.[j|t]s' 2> /dev/null) " ]; then
67- yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=2 --forceExit --silent=false --verbose --bail --testPathPattern ' /domains/' $domain_name ' /(.*)[.]spec.[j|t]s$' 2>&1 > ' /app/test_logs/condo.' $domain_name ' .specs.log'
68- else
69- echo " Files matching (.*)[.]spec.[j|t]s in directory apps/condo/domains/$domain_name not found! Skipping..."
70- fi
71- # Note: we need to stop background worker! because packages tests use the same redis queue
72- kill $( jobs -p) || echo ' background worker and dev server is already killed!'
73- killall node || echo ' no node processes'
74- else
75- # TESTS
76- yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=3 --forceExit --silent=false --verbose --bail --testPathPattern ' /schema/(.*)[.]test.js$' --testPathIgnorePatterns=' /domains/(organization|user|scope|property|acquiring|billing|miniapp|banking|ticket|meter|contact|resident|notification|common)/' 2>&1 > /app/test_logs/condo.others.tests.log
77- yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=3 --forceExit --silent=false --verbose --bail --testPathPattern ' (.*)[.]test.js$' --testPathIgnorePatterns=' /schema/(.*)[.]test.js$' 2>&1 > /app/test_logs/condo.5.test.others.log
78- # SPECS
79- yarn workspace @app/condo test --workerIdleMemoryLimit=" 256MB" --testTimeout=15000 -w=2 --forceExit --silent=false --verbose --bail --testPathPattern ' (.*)[.]spec.[j|t]s$' --testPathIgnorePatterns=' /domains/(organization|user|scope|property|acquiring|billing|miniapp|banking|ticket|meter|contact|resident|notification|common)/' 2>&1 > /app/test_logs/condo.others.specs.log
80- # Note: we need to stop background worker! because packages tests use the same redis queue
81- kill $( jobs -p) || echo ' background worker and dev server is already killed!'
82- killall node || echo ' no node processes'
119+ if [ " $shard_index " -lt 1 ] || [ " $shard_total " -lt 1 ] || [ " $shard_index " -gt " $shard_total " ]; then
120+ echo " Invalid shard values: shard_index=$shard_index shard_total=$shard_total "
121+ exit 1
122+ fi
83123
124+ setup_and_start_services
125+
126+ # TESTS (.test.js)
127+ yarn workspace @app/condo test \
128+ --workerIdleMemoryLimit=" 256MB" \
129+ --testTimeout=15000 \
130+ -w=3 \
131+ --forceExit \
132+ --silent=false \
133+ --verbose \
134+ --bail \
135+ --testPathPattern ' (.*)[.]test.js$' \
136+ --shard=" $shard_index /$shard_total " \
137+ 2>&1 > " /app/test_logs/condo.shard-${shard_index} -of-${shard_total} .tests.log"
138+
139+ # SPECS (.spec.js|.spec.ts)
140+ yarn workspace @app/condo test \
141+ --workerIdleMemoryLimit=" 256MB" \
142+ --testTimeout=15000 \
143+ -w=2 \
144+ --forceExit \
145+ --silent=false \
146+ --verbose \
147+ --bail \
148+ --testPathPattern ' (.*)[.]spec.[j|t]s$' \
149+ --shard=" $shard_index /$shard_total " \
150+ 2>&1 > " /app/test_logs/condo.shard-${shard_index} -of-${shard_total} .specs.log"
151+
152+ stop_services
153+
154+ # Run non-domain tests that were previously executed in "others"
155+ if [ " $shard_index " -eq 1 ]; then
84156 # TODO: INFRA-155 Remove it completely by rewriting a task tests or migrate to jest.setup or smth
85157 REDIS_URL=' [{"port":7001,"host":"127.0.0.1"},{"port":7002,"host":"127.0.0.1"},{"port":7003,"host":"127.0.0.1"}]' yarn workspace @open-condo/keystone test
86158 yarn workspace @app/condo lint-schema
0 commit comments