Skip to content

Commit e1b2e2b

Browse files
Gioeemarcobambini
andauthored
new integration test (#4)
* feat: init integration tests * fix: optimize build commands and improve CPU utilization in Makefile * New Android PEM specific code * fix android cert: add new line * refactor: remove health-track schema and update db_init function for improved initialization * refactor: improve error handling and add in memory peers test * refactor: multi-threaded sync testing with random text insert * expect sync to be gt0 only when not initializing the db * to fix test * test only 5 peers * test 2 peers * test: expect changes gt0 only when not initializing the db * test: low peers count * fix integration test: add windows thread handling * fix: rename INT to INTGR in expected_type enum to avoid redeclaration issues * test 1 peer * add max retry and wait time * increase wait time and retries * Resolve cacert.h merge conflicts * test print network sync results * sync test skip insert * test print network init string * test: remove debug prints * test: update PEERS count and modify cloudsync_network_sync parameters * test: lower peers count * test: missing close database connection after initialization * linux error test * revert last test commit * test debug functions and settings * test 1 peer * test 2 peer * print cloudsync_network_sync * test: disable debug flags * test more peers * final test 50 peers * remove debug network sync print * test 10 peers * expect network sync to be gt0 * hardcode test executables * fix makefile link pthread * revert last commits * lower peers count --------- Co-authored-by: Marco Bambini <[email protected]>
1 parent 293d7e3 commit e1b2e2b

File tree

4 files changed

+369
-17
lines changed

4 files changed

+369
-17
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ jobs:
4848
run:
4949
shell: bash
5050

51+
env:
52+
CONNECTION_STRING: ${{ secrets.CONNECTION_STRING }}
53+
APIKEY: ${{ secrets.APIKEY }}
54+
WEBLITE: ${{ secrets.WEBLITE }}
55+
5156
steps:
5257

5358
- uses: actions/[email protected]
@@ -62,11 +67,11 @@ jobs:
6267
6368
- name: windows build curl
6469
if: matrix.os == 'windows-latest'
65-
run: make curl/windows/libcurl.a -j4
70+
run: make curl/windows/libcurl.a
6671
shell: msys2 {0}
6772

6873
- name: build sqlite-sync
69-
run: make extension ${{ matrix.make && matrix.make || ''}} -j4
74+
run: make extension ${{ matrix.make && matrix.make || ''}}
7075

7176
- name: windows install sqlite3
7277
if: matrix.os == 'windows-latest'
@@ -96,10 +101,13 @@ jobs:
96101
echo "::endgroup::"
97102
98103
echo "::group::prepare the test script"
99-
make test PLATFORM=$PLATFORM ARCH=$ARCH -j4 || echo "It should fail. Running remaining commands in the emulator"
104+
make test PLATFORM=$PLATFORM ARCH=$ARCH || echo "It should fail. Running remaining commands in the emulator"
100105
cat > commands.sh << EOF
101106
mv -f /data/local/tmp/sqlite3 /system/xbin
102107
cd /data/local/tmp
108+
export CONNECTION_STRING="$CONNECTION_STRING"
109+
export APIKEY="$APIKEY"
110+
export WEBLITE="$WEBLITE"
103111
$(make test PLATFORM=$PLATFORM ARCH=$ARCH -n)
104112
EOF
105113
echo "::endgroup::"
@@ -118,7 +126,7 @@ jobs:
118126
119127
- name: test sqlite-sync
120128
if: matrix.name == 'linux' || matrix.name == 'windows'
121-
run: make test -j4
129+
run: make test
122130

123131
- name: test sqlite-sync + coverage
124132
if: matrix.name == 'macos'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
*.a
1111
unittest
1212
/curl/src
13+
.vscode

Makefile

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ CURL_VERSION ?= 8.12.1
1111
# Set default platform if not specified
1212
ifeq ($(OS),Windows_NT)
1313
PLATFORM := windows
14-
HOST:= windows
14+
HOST := windows
15+
CPUS := $(shell powershell -Command "[Environment]::ProcessorCount")
1516
else
1617
HOST = $(shell uname -s | tr '[:upper:]' '[:lower:]')
1718
ifeq ($(HOST),darwin)
1819
PLATFORM := macos
20+
CPUS := $(shell sysctl -n hw.ncpu)
1921
else
2022
PLATFORM := $(HOST)
23+
CPUS := $(shell nproc)
2124
endif
2225
endif
2326

27+
# Speed up builds by using all available CPU cores
28+
MAKEFLAGS += -j$(CPUS)
29+
2430
# Compiler and flags
2531
CC = gcc
2632
CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR) -I$(SQLITE_DIR) -I$(CURL_DIR)/include
@@ -42,18 +48,14 @@ CURL_SRC = $(CURL_DIR)/src/curl-$(CURL_VERSION)
4248
COV_DIR = coverage
4349
CUSTOM_CSS = $(TEST_DIR)/sqliteai.css
4450

45-
# Files and objects
46-
ifeq ($(PLATFORM),windows)
47-
TEST_TARGET := $(DIST_DIR)/test.exe
48-
else
49-
TEST_TARGET := $(DIST_DIR)/test
50-
endif
5151
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
52-
TEST_FILES = $(SRC_FILES) $(wildcard $(TEST_DIR)/*.c) $(wildcard $(SQLITE_DIR)/*.c)
52+
TEST_SRC = $(wildcard $(TEST_DIR)/*.c)
53+
TEST_FILES = $(SRC_FILES) $(TEST_SRC) $(wildcard $(SQLITE_DIR)/*.c)
5354
RELEASE_OBJ = $(patsubst %.c, $(BUILD_RELEASE)/%.o, $(notdir $(SRC_FILES)))
5455
TEST_OBJ = $(patsubst %.c, $(BUILD_TEST)/%.o, $(notdir $(TEST_FILES)))
5556
COV_FILES = $(filter-out $(SRC_DIR)/lz4.c $(SRC_DIR)/network.c, $(SRC_FILES))
5657
CURL_LIB = $(CURL_DIR)/$(PLATFORM)/libcurl.a
58+
TEST_TARGET = $(patsubst %.c,$(DIST_DIR)/%$(EXE), $(notdir $(TEST_SRC)))
5759

5860
# Platform-specific settings
5961
ifeq ($(PLATFORM),windows)
@@ -64,6 +66,7 @@ ifeq ($(PLATFORM),windows)
6466
DEF_FILE := $(BUILD_RELEASE)/cloudsync.def
6567
CFLAGS += -DCURL_STATICLIB
6668
CURL_CONFIG = --with-schannel CFLAGS="-DCURL_STATICLIB"
69+
EXE = .exe
6770
else ifeq ($(PLATFORM),macos)
6871
TARGET := $(DIST_DIR)/cloudsync.dylib
6972
LDFLAGS += -arch x86_64 -arch arm64 -framework Security -dynamiclib -undefined dynamic_lookup
@@ -90,7 +93,7 @@ else ifeq ($(PLATFORM),android)
9093

9194
OPENSSL := $(BIN)/../sysroot/usr/include/openssl
9295
CC = $(BIN)/$(ARCH)-linux-android26-clang
93-
CURL_CONFIG = --host $(ARCH)-$(HOST)-android26 --with-openssl=$(BIN)/../sysroot/usr LIBS="-lssl -lcrypto" AR=$(BIN)/llvm-ar AS=$(BIN)/llvm-as CC=$(BIN)/$(ARCH)-linux-android26-clang CXX=$(BIN)/$(ARCH)-linux-android26-clang++ LD=$(BIN)/ld RANLIB=$(BIN)/llvm-ranlib STRIP=$(BIN)/llvm-strip
96+
CURL_CONFIG = --host $(ARCH)-$(HOST)-android26 --with-openssl=$(BIN)/../sysroot/usr LIBS="-lssl -lcrypto" AR=$(BIN)/llvm-ar AS=$(BIN)/llvm-as CC=$(CC) CXX=$(BIN)/$(ARCH)-linux-android26-clang++ LD=$(BIN)/ld RANLIB=$(BIN)/llvm-ranlib STRIP=$(BIN)/llvm-strip
9497
TARGET := $(DIST_DIR)/cloudsync.so
9598
LDFLAGS += -shared -lcrypto -lssl
9699
else ifeq ($(PLATFORM),ios)
@@ -146,20 +149,20 @@ endif
146149

147150
# Test executable
148151
$(TEST_TARGET): $(TEST_OBJ)
149-
$(CC) $(TEST_OBJ) -o $@ $(T_LDFLAGS)
152+
$(CC) $(filter-out $(patsubst $(DIST_DIR)/%$(EXE),$(BUILD_TEST)/%.o, $(filter-out $@,$(TEST_TARGET))), $(TEST_OBJ)) -o $@ $(T_LDFLAGS)
150153

151154
# Object files
152155
$(BUILD_RELEASE)/%.o: %.c
153156
$(CC) $(CFLAGS) -O3 -fPIC -c $< -o $@
154157
$(BUILD_TEST)/sqlite3.o: $(SQLITE_DIR)/sqlite3.c
155-
$(CC) $(CFLAGS) -DSQLITE_CORE=1 -c $< -o $@
158+
$(CC) $(CFLAGS) -DSQLITE_CORE -c $< -o $@
156159
$(BUILD_TEST)/%.o: %.c
157160
$(CC) $(T_CFLAGS) -c $< -o $@
158161

159162
# Run code coverage (--css-file $(CUSTOM_CSS))
160163
test: $(TARGET) $(TEST_TARGET)
161164
$(SQLITE3) ":memory:" -cmd ".bail on" ".load ./$<" "SELECT cloudsync_version();"
162-
./$(TEST_TARGET)
165+
set -e; for t in $(TEST_TARGET); do ./$$t; done
163166
ifneq ($(COVERAGE),false)
164167
mkdir -p $(COV_DIR)
165168
lcov --capture --directory . --output-file $(COV_DIR)/coverage.info $(subst src, --include src,${COV_FILES})
@@ -265,7 +268,7 @@ endif
265268

266269
# Clean up generated files
267270
clean:
268-
rm -rf $(BUILD_DIRS) $(DIST_DIR)/* $(COV_DIR) *.gcda *.gcno *.gcov $(CURL_DIR)/src
271+
rm -rf $(BUILD_DIRS) $(DIST_DIR)/* $(COV_DIR) *.gcda *.gcno *.gcov $(CURL_DIR)/src *.sqlite
269272

270273
# Help message
271274
help:

0 commit comments

Comments
 (0)