Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1380ef51 authored by Evgenii Stepanov's avatar Evgenii Stepanov Committed by Android (Google) Code Review
Browse files

Merge "Deflake testKeyValue_Concurrency."

parents 7d3ea1c8 6c34ede6
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -122,20 +122,18 @@ public class LockSettingsStorageTests extends AndroidTestCase {
    }

    public void testKeyValue_Concurrency() {
        final Object monitor = new Object();
        final CountDownLatch latch = new CountDownLatch(1);
        List<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            final int threadId = i;
            threads.add(new Thread("testKeyValue_Concurrency_" + i) {
                @Override
                public void run() {
                    synchronized (monitor) {
                    try {
                            monitor.wait();
                        latch.await();
                    } catch (InterruptedException e) {
                        return;
                    }
                    }
                    mStorage.writeKeyValue("key", "1 from thread " + threadId, 0);
                    mStorage.readKeyValue("key", "default", 0);
                    mStorage.writeKeyValue("key", "2 from thread " + threadId, 0);
@@ -151,9 +149,7 @@ public class LockSettingsStorageTests extends AndroidTestCase {
            threads.get(i).start();
        }
        mStorage.writeKeyValue("key", "initalValue", 0);
        synchronized (monitor) {
            monitor.notifyAll();
        }
        latch.countDown();
        joinAll(threads, 10000);
        assertEquals('5', mStorage.readKeyValue("key", "default", 0).charAt(0));
        mStorage.clearCache();