From cd15bc3e8dbed5b027497185b7bb7f30f2c49ea8 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 25 Feb 2019 17:01:22 -0500 Subject: A thread stress test (cherry picked from commit bc948ac1a5dca4d0a305a265de157d7505e4a4b2) --- tests/test_data.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/test_data.py b/tests/test_data.py index 3f96288f..417f9771 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -9,6 +9,7 @@ import os import os.path import re import sqlite3 +import threading import mock @@ -455,6 +456,21 @@ class CoverageDataTest(DataTestHelpers, CoverageTest): covdata2.read() self.assert_arcs3_data(covdata2) + def test_thread_stress(self): + covdata = CoverageData() + + def thread_main(): + """Every thread will try to add the same data.""" + covdata.add_lines(LINES_1) + + threads = [threading.Thread(target=thread_main) for _ in range(10)] + for t in threads: + t.start() + for t in threads: + t.join() + + self.assert_lines1_data(covdata) + class CoverageDataTestInTempDir(DataTestHelpers, CoverageTest): """Tests of CoverageData that need a temporary directory to make files.""" -- cgit v1.2.1