Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOM when run many tests in one launch #272

Closed
dalapenko opened this issue Feb 28, 2024 · 2 comments
Closed

OOM when run many tests in one launch #272

dalapenko opened this issue Feb 28, 2024 · 2 comments

Comments

@dalapenko
Copy link

dalapenko commented Feb 28, 2024

Hello. When I try to launch all my screenshot tests I'm get error:

    java.lang.OutOfMemoryError: Java heap space
        at java.desktop/java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
        at java.desktop/java.awt.image.Raster.createPackedRaster(Raster.java:539)
        at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
        at java.desktop/java.awt.image.BufferedImage.<init>(BufferedImage.java:333)
        at com.github.takahirom.roborazzi.BitmapToBufferedImageConverter.convert(BitmapToBufferedImageConverter.kt:12)
        at com.github.takahirom.roborazzi.AwtRoboCanvas$drawImage$1.invoke(AwtRoboCanvas.kt:49)
        at com.github.takahirom.roborazzi.AwtRoboCanvas$drawImage$1.invoke(AwtRoboCanvas.kt:47)
        at com.github.takahirom.roborazzi.AwtRoboCanvasKt.graphics(AwtRoboCanvas.kt:579)
        at com.github.takahirom.roborazzi.AwtRoboCanvasKt.access$graphics(AwtRoboCanvas.kt:1)
        at com.github.takahirom.roborazzi.AwtRoboCanvas.drawImage(AwtRoboCanvas.kt:47)
        at com.github.takahirom.roborazzi.RoborazziKt.capture(Roborazzi.kt:621)
        at com.github.takahirom.roborazzi.ImageCaptureViewAction.perform(Roborazzi.kt:587)
        at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:2)
        at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:25)
        at androidx.test.espresso.ViewInteraction.-$$Nest$mdoPerform(ViewInteraction.java)
        at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:7)
        at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:1)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at android.os.Handler.$$robo$$android_os_Handler$handleCallback(Handler.java:942)
        at java.base/java.lang.invoke.LambdaForm$DMH/0x00000008002e5800.invokeStatic(LambdaForm$DMH)
        at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002f2000.guardWithCatch(LambdaForm$MH)
        at java.base/java.lang.invoke.DelegatingMethodHandle$Holder.delegate(DelegatingMethodHandle$Holder)
        at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002f3000.guard(LambdaForm$MH)
        at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002f3400.linkToCallSite(LambdaForm$MH)
        at android.os.Handler.handleCallback(Handler.java)
        at android.os.Handler.$$robo$$android_os_Handler$dispatchMessage(Handler.java:99)
        at java.base/java.lang.invoke.LambdaForm$DMH/0x00000008002e5000.invokeSpecial(LambdaForm$DMH)
        at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002fac00.guardWithCatch(LambdaForm$MH)
        at java.base/java.lang.invoke.DelegatingMethodHandle$Holder.delegate(DelegatingMethodHandle$Holder)
        at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002fc400.guard(LambdaForm$MH)
        at java.base/java.lang.invoke.LambdaForm$MH/0x00000008002fc800.linkToCallSite(LambdaForm$MH)
        at android.os.Handler.dispatchMessage(Handler.java)

Doesn't matter run from AS or gradle command line. It's throw after ~160 tests in one launch. If I try to start it separated by class, where max tests in one class ~90 it's ok. I tried to make sample of problem with simple views, but problem not reproduced. In my production project with more complex view - throws "out of memory" :(. Do you have any idea about problem?

upd: org.gradle.jvmargs=-Xmx4096M

@takahirom
Copy link
Owner

takahirom commented Feb 29, 2024

@dalapenko
Thanks!
First of all, if the baseline memory allocation is insufficient, consider adjusting the heap size for unit tests by using unitTests.maxHeapSize as follows:

android {
  ...
  testOptions {
    unitTests.all {
      maxHeapSize = "4096m"
    }
  }
}

https://support.circleci.com/hc/en-us/articles/360021812453-Common-Android-memory-issues

Additionally, there may be memory leaks in your tests due to activities being retained in static fields. You can identify such leaks using VisualVM. Simply launch VisualVM and select the process of your tests during execution to monitor and check for leaks.

@dalapenko
Copy link
Author

Yep, it was helpful. Thanks. I didn't find leak, everything looks normally, but max heap was 1024M and in runtime max used may amount ~1300-1400M. Increased maxHeapSize for unit Tests and it's ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants