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

Commit 63730ba3 authored by Kweku Adams's avatar Kweku Adams
Browse files

Add test for PendingJobQueue.

Test that removing while iterating doesn't negatively affect iteration.

Bug: 141645789
Test: atest FrameworksServicesTests:PendingJobQueueTest
Change-Id: I13d3d5ffe4946bbc4851e18a622de9f2fb63e948
parent d7c5239f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -219,6 +219,8 @@ class PendingJobQueue {
            ajq.clear();
            mAppJobQueuePool.release(ajq);
        } else if (prevTimestamp != ajq.peekNextTimestamp()) {
            // Removing the job changed the "next timestamp" in the queue, so we need to reinsert
            // it to fix the ordering.
            mOrderedQueues.remove(ajq);
            mOrderedQueues.offer(ajq);
        }
+26 −0
Original line number Diff line number Diff line
@@ -201,6 +201,32 @@ public class PendingJobQueueTest {
            }
        }
        assertNull(jobQueue.next());
        assertEquals(0, jobQueue.size());
    }

    @Test
    public void testRemove_duringIteration() {
        List<JobStatus> jobs = new ArrayList<>();
        jobs.add(createJobStatus("testRemove", createJobInfo(1), 1));
        jobs.add(createJobStatus("testRemove", createJobInfo(2), 2));
        jobs.add(createJobStatus("testRemove", createJobInfo(3).setExpedited(true), 3));
        jobs.add(createJobStatus("testRemove", createJobInfo(4), 4));
        jobs.add(createJobStatus("testRemove", createJobInfo(5).setExpedited(true), 5));

        PendingJobQueue jobQueue = new PendingJobQueue();
        jobQueue.addAll(jobs);

        ArraySet<JobStatus> removed = new ArraySet<>();
        JobStatus job;
        jobQueue.resetIterator();
        while ((job = jobQueue.next()) != null) {
            jobQueue.remove(job);
            removed.add(job);
            assertFalse("Queue retained a removed job " + testJobToString(job),
                    jobQueue.contains(job));
        }
        assertNull(jobQueue.next());
        assertEquals(0, jobQueue.size());
    }

    @Test