mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

Since 1.3.10: "Data provider exceeds the limit specified by the query" #100

Closed klauss42 closed 2 years ago

klauss42 commented 2 years ago

Since upgrading to Karibu testing 1.3.10 we get the following error for a simple grid test that worked fine so far:

java.lang.IllegalStateException: The number of items returned by the data provider exceeds the limit specified by the query (1).

    at com.vaadin.flow.data.provider.DataCommunicator$SizeVerifier.accept(DataCommunicator.java:249)
    at java.base/java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:441)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
    at kotlin.streams.jdk8.StreamsKt.toList(Streams.kt:72)
    at com.github.mvysny.kaributesting.v10.GridKt.fetch(Grid.kt:173)
    at com.github.mvysny.kaributesting.v10.GridKt._fetch(Grid.kt:131)
    at com.github.mvysny.kaributesting.v10.GridKt._getOrNull(Grid.kt:101)
    at com.github.mvysny.kaributesting.v10.GridKt._get(Grid.kt:77)

Code snippet:

    val grid = _get<Grid<EstimateViewModel>> { id = "estimates-grid" }
    grid.expectRows(2)
    println(grid.dataCommunicator.isPagingEnabled) // <- paging is enabled
    grid._get(0).estimateNumber // <<----here the exception is thrown

I think this has been introduced by changes for issue #99

I have no idea for a workaround so far

mvysny commented 2 years ago

Hi Klaus, yeah it could indeed be related to #99. Just thinking out loud: which DataProvider implementation are you using please? Perhaps there's a bug in the DataProvider implementation which returns more data than the Query asks for? Currently the Query will ask for 1 (one) item only (thanks to #99).

klauss42 commented 2 years ago

Hey Martin The dataProvider used in the test is a mocked variant of an AbstractBackendDataProvider which worked properly for quite some time already.

The problem is the current implementation of the _get(). If I use _fetch() instead of _get(), the test would suceed:

val grid = _get<Grid<EstimateViewModel>>(){ id = "estimates-grid" }
val size = grid.dataCommunicator.itemCount // size == 2
val list = grid._fetch(0, 10)  // list of 2 elements
assertThat(list[0].estimateNumber).isEqualTo("estimateNumber") // succeeds
assertThat(grid._get(0).estimateNumber).isEqualTo("estimateNumber") // <= FAILS

I hope this helps

Greetz from Hamburg BTW: Your code from last summer is still working rock solid:-)

Klaus

mvysny commented 2 years ago

Haha, love to hear that :-D Greetings to Hamburg from Finland :+1: :wave:

Could it be that your mocked DataProvider always returns 2 items? If yes, then I think that grid._fetch(0,1) should fail as well. Could you briefly return just one item from your data provider, to see whether that would fix the exception?

klauss42 commented 2 years ago

Hey again. Yes, you're right. _fetch(0,1) also fails. I have to review our data provider mock mock

klauss42 commented 2 years ago

Confirmed. If the data provider mock just returns 1 item if, the exception in _get() is gone. I have to fix our mock, so that it handles the limit param properly