objectbox / objectbox/objectbox-java

Multiple emissions from a data subscription when one is expected, after quickly recreating box store

Đang mở
#695 7 bình luận 0 reaction 1 người được giao Xem trên GitHub

@greenrobot-team đang làm issue này rồi.

Từ ngày 10/12/2019.

enhancement help wanted
Ngôn ngữ chính
Java
Star
4.6k
Fork
311
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Issue Basics

  • ObjectBox version: 2.3.4
  • Reproducibility: Always

Reproducing the bug

Description

While running multiple JUnit tests for an ObjectBox store (using base code copied from https://docs.objectbox.io/android/android-local-unit-tests#create-a-local-unit-test-class), I noticed a strange issue where if I was putting an initial object into the box before every test, I would sometimes be receiving more emissions than I had expected. It turns out that after the first test is run and the base test code (referenced above) is run to close/delete the BoxStore and then create it again (in the @After and @Before annotated methods), subsequent tests would be receiving two emissions (even though only one is expected).

After doing some digging, I thought that this might possibly be coming from the BoxStore's internal thread pool (similar to #616). I added code to essentially "complete" the thread pool before moving onto a new test, by submitting an empty runnable and waiting for it to complete, and that appears to have stopped the described multiple emission issue. That being said I'm not quite sure how this is happening, since the store is being completely recreated (and seemingly shutting down its internal thread pool), so I'm not sure how an emission from a previous publisher would be coming through to the next observer.

Code

Example tests can be found/run from this repository: https://github.com/jsoberg/Objectbox-Java-MultipleEmissionBug. Issue is observed when running all tests in the UnexpectedMultipleEmissionBugTest test class. When all tests are run in this class at once, test1() will execute as expected, while test2() (performing the exact same actions) will fail, as it is asserting a single value but ends up getting 2. If each test method is run individually, they will pass as expected.

Misc

Workaround was implemented (https://github.com/jsoberg/Objectbox-Java-MultipleEmissionBug) in test class ExpectedSingleEmissionTest. In this tests testSetup() method, I submitted an empty runnable and waited for it to complete after pushing my initial entity.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.