objectbox / objectbox/objectbox-java

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

オープン
#695 コメント 7 件 リアクション 0 件 担当者 1 名 GitHub で見る

@greenrobot-team がすでに取り組んでいます。

2019年12月10日 から。

enhancement help wanted
主要言語
Java
スター
4.6k
フォーク
311
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。