-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_parallel_writes.py
101 lines (58 loc) · 2.28 KB
/
test_parallel_writes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import pytest
from database import create_table, row_count, insert_row
from utils import (
insert_rows_in_parallel,
insert_rows_in_parallel_cf,
generate_example_rows,
)
def test_adding_5_rows_in_parallel_to_new_db():
# Create a new `messages` sqlite3 table,
# dropping it if one already exists.
create_table()
assert row_count() == 0
# Run 5 parallel instances of `insert_rows`
# by way of `insert_rows_in_parallel`
insert_rows_in_parallel(generate_example_rows(5))
assert row_count() == 5
def test_adding_50_rows_in_parallel_to_new_db():
create_table()
assert row_count() == 0
insert_rows_in_parallel(generate_example_rows(50))
assert row_count() == 50
def test_adding_250_rows_in_parallel_to_new_db():
create_table()
assert row_count() == 0
insert_rows_in_parallel(generate_example_rows(250))
assert row_count() == 250
def test_adding_250_rows_in_parallel_to_new_db_cf():
create_table()
assert row_count() == 0
insert_rows_in_parallel_cf(generate_example_rows(250))
assert row_count() == 250
def test_adding_50_rows_to_populated_db():
# Row count from previous test should remain unchanged
assert row_count() == 250
insert_rows_in_parallel(generate_example_rows(50))
assert row_count() == 300
def test_adding_10000_rows_sequentially_then_100_rows_in_parallel():
create_table()
assert row_count() == 0
for example_row in generate_example_rows(10000):
insert_row(example_row)
assert row_count() == 10000
insert_rows_in_parallel(generate_example_rows(100))
assert row_count() == 10100
def test_adding_250_rows_in_parallel_to_new_db_wal_mode_enabled():
# After creating the database, enable WAL mode.
# https://www.sqlite.org/pragma.html#pragma_journal_mode
create_table(enable_wal_mode=True)
assert row_count() == 0
insert_rows_in_parallel(generate_example_rows(250))
assert row_count() == 250
def test_adding_500_rows_in_parallel_to_new_db_wal_mode_enabled():
# After creating the database, enable WAL mode.
# https://www.sqlite.org/pragma.html#pragma_journal_mode
create_table(enable_wal_mode=True)
assert row_count() == 0
insert_rows_in_parallel(generate_example_rows(500))
assert row_count() == 500