Skip to content

Commit b0960a8

Browse files
committed
add Valgrind test script and run it from CI; fix issues in tests
closes #72
1 parent 37c46c9 commit b0960a8

File tree

6 files changed

+83
-9
lines changed

6 files changed

+83
-9
lines changed

.github/workflows/dart.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name: Build and test
22

3-
on: [push, pull_request]
3+
on: [ push, pull_request ]
4+
5+
defaults:
6+
run:
7+
shell: bash
48

59
jobs:
610
generator:
711
runs-on: ubuntu-20.04
812
container:
9-
image: google/dart:latest
13+
image: google/dart:latest
1014
steps:
1115
- uses: actions/checkout@v1
1216
- name: Install ObjectBox C-API
@@ -15,17 +19,31 @@ jobs:
1519
run: ./generator/test.sh
1620

1721
lib:
18-
needs: generator
1922
runs-on: ubuntu-20.04
2023
container:
21-
image: google/dart:latest
24+
image: google/dart:latest
2225
steps:
2326
- uses: actions/checkout@v1
2427
- name: Install ObjectBox C-API
2528
run: ./install.sh
26-
- name: Install dependencies
27-
run: pub get
2829
- name: Generate ObjectBox models
2930
run: pub run build_runner build
3031
- name: Run tests
3132
run: pub run test
33+
34+
valgrind:
35+
runs-on: ubuntu-20.04
36+
container:
37+
image: google/dart:latest
38+
steps:
39+
- uses: actions/checkout@v1
40+
- name: Install ObjectBox C-API
41+
run: ./install.sh
42+
- run: pub get
43+
- name: Install Valgrind
44+
run: |
45+
apt update
46+
apt install -y valgrind
47+
- name: Generate ObjectBox models
48+
run: pub run build_runner build
49+
- run: ./tool/valgrind.sh

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Default target executed when no arguments are given to make.
22
default: all
33

4-
.PHONY: default help depend test publish integration-test
4+
.PHONY: default help depend test valgrind-test publish integration-test
55

66
help: ## Show this help
77
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -18,6 +18,10 @@ test: ## Test all targets
1818
pub run build_runner build
1919
pub run test
2020

21+
valgrind-test: ## Test all targets with valgrind
22+
pub run build_runner build
23+
./tool/valgrind.sh
24+
2125
integration-test: ## Execute integration tests
2226
cd example/flutter/objectbox_demo/ ; \
2327
flutter pub get ; \

test/query_property_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ void main() {
118118
final qp = query.property(tString);
119119
expect(qp is StringPropertyQuery, true);
120120
qp.close();
121+
122+
query.close();
121123
});
122124

123125
final add = (a, b) => a + b;
@@ -415,6 +417,8 @@ void main() {
415417
queryAndCheck(tShort, -2, 'short null->negative');
416418
queryAndCheck(tInt, -2, 'int null->negative');
417419
queryAndCheck(tLong, -2, 'long null->negative');
420+
421+
queryStrings.close();
418422
});
419423

420424
test('.find() replace null floats', () {
@@ -431,6 +435,8 @@ void main() {
431435

432436
queryAndCheck(tDouble, 1337.0, 'null double');
433437
queryAndCheck(tFloat, 1337.0, 'null float');
438+
439+
queryIntegers.close();
434440
});
435441

436442
test('.find() replace null strings', () {
@@ -441,6 +447,7 @@ void main() {
441447
final qp = queryFloats.stringProperty(tString);
442448
expect(qp.find(replaceNullWith: 't').first, 't');
443449
qp.close();
450+
queryFloats.close();
444451
});
445452

446453
test('.distinct, .count, .close property query', () {

test/query_test.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void main() {
4141

4242
expect(q.count(), 1);
4343
expect(q.findFirst().ignore, null);
44+
45+
q.close();
4446
});
4547

4648
test('ignore multiple transient fields', () {
@@ -60,6 +62,8 @@ void main() {
6062
expect(q.count(), 1);
6163
expect(result.disregard, null);
6264
expect(result.omit, null);
65+
66+
q.close();
6367
});
6468

6569
test('.null and .notNull', () {
@@ -290,11 +294,12 @@ void main() {
290294
box.put(TestEntity(tString: largeString));
291295
box.put(TestEntity(tString: largeString));
292296

293-
List<TestEntity> items =
294-
box.query(TestEntity_.id.lessThan(3)).build().find();
297+
final query = box.query(TestEntity_.id.lessThan(3)).build();
298+
List<TestEntity> items = query.find();
295299
expect(items.length, 2);
296300
expect(items[0].tString, largeString);
297301
expect(items[1].tString, largeString);
302+
query.close();
298303
});
299304

300305
test('.remove deletes the right items', () {

test/stream_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void main() {
4747
expect(result, ['Hello world', 'for now, Goodbye, Hello world']);
4848

4949
await subscription.cancel();
50+
query.close();
5051
});
5152

5253
test('Subscribe to stream of query', () async {
@@ -72,6 +73,7 @@ void main() {
7273
expect(result, [1, 3]);
7374

7475
await subscription.cancel();
76+
query.close();
7577
});
7678

7779
test(

tool/valgrind.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
. "$(dirname "$0")"/common.sh
2+
3+
if [[ "$#" -gt "1" ]]; then
4+
echo "usage: $0 [test name]"
5+
echo "e.g. $0"
6+
echo "or $0 query"
7+
exit 1
8+
fi
9+
10+
testDir="${root}/build/test/valgrind"
11+
rm -rf "${testDir}"
12+
mkdir -pv "${testDir}"
13+
cd "${testDir}" || exit 1
14+
15+
16+
function testWithValgrind() {
17+
echo "Running $1 with valgrind"
18+
19+
dart2native "${root}/test/${1}" --output ./test --verbose
20+
valgrind --show-mismatched-frees=no --leak-check=full --error-exitcode=1 ./test
21+
22+
echo "$1 successful - no errors reported by valgrind"
23+
echo "--------------------------------------------------------------------------------"
24+
}
25+
26+
if [[ "$#" -gt "0" ]]; then
27+
testWithValgrind "${1}_test.dart"
28+
else
29+
for file in "${root}/test/"*_test.dart
30+
do
31+
testWithValgrind $(basename $file)
32+
done
33+
find "${root}/test/" -name "*_test.dart" -type f -exec testWithValgrind {} \;
34+
fi
35+
36+
echo "Test passed, cleaning up"
37+
cd "${root}" || exit 1
38+
rm -rf "${testDir}"

0 commit comments

Comments
 (0)