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

Unit tests spying frequently called methods slow #258

Closed
jzy3d opened this issue Apr 30, 2022 · 2 comments · Fixed by #259
Closed

Unit tests spying frequently called methods slow #258

jzy3d opened this issue Apr 30, 2022 · 2 comments · Fixed by #259
Projects

Comments

@jzy3d
Copy link
Owner

jzy3d commented Apr 30, 2022

  • TestContinuousAndOnDemandRendering (approx. 20sec)
  • TestDepthRange (approx. 30sec)

It seams this occur with objects that may be called frequently (Painter, Camera, View, etc)

@jzy3d jzy3d added the bug label Apr 30, 2022
@jzy3d
Copy link
Owner Author

jzy3d commented Apr 30, 2022

@jzy3d jzy3d changed the title Unit tests spying frequently called objects are slow Unit tests spying frequently called objects methods slow Apr 30, 2022
@jzy3d
Copy link
Owner Author

jzy3d commented Apr 30, 2022

Performance improves a lot when doing "manual mocks", i.e. override the class and method to spy instead of asking Mockito generate the spy. A 30s test dropped to < 1s.

Here we want to check how many time the method glDepthRange was called with which arguments :

public class GLMock_DepthRange extends GL{
  List<double[]> verify_glDepthRange = new ArrayList<>();
  
  @Override
  public void glDepthRange(double near_val, double far_val) {
    super.glDepthRange(near_val, far_val);
    double[] args = {near_val, far_val};
    verify_glDepthRange.add(args);
  }
  public List<double[]> verify_glDepthRange() {
    return verify_glDepthRange;
  }
  public void clear_glDepthRange() {
    verify_glDepthRange.clear();
  }
}

And use it as follow

public class TestAxisBox {
  @Test
  public void whenRenderAxis_DepthRangeModifiedByAxis() {
    GLMock_DepthRange glMock = new GLMock_DepthRange();

    // Given a surface chart with a mock GL injected for spying calls to glDepthRange
    EmulGLChartFactory factory = EmulGLChartFactory.forGL(glMock);
    Chart chart = factory.newChart(Quality.Advanced());
    Shape surface = SampleGeom.surface();
    chart.add(surface);
    glMock.clear_glDepthRange();

    // ----------------------------------------------
    // When : render axis
    chart.getView().getAxis().draw(chart.getPainter());

    // ----------------------------------------------
    // Then axis will update depth range
    double[] configForAxis = {AxisBox.NO_OVERLAP_DEPTH_RATIO, 1};
    double[] configForNothing = {0, 1};

    Assert.assertTrue(Arrays.equals(glMock.verify_glDepthRange().get(0), configForAxis));
    Assert.assertTrue(Arrays.equals(glMock.verify_glDepthRange().get(1), configForNothing));

  }
}

@jzy3d jzy3d changed the title Unit tests spying frequently called objects methods slow Unit tests spying frequently called methods slow Apr 30, 2022
@jzy3d jzy3d removed the bug label May 1, 2022
@jzy3d jzy3d closed this as completed in #259 May 9, 2022
@jzy3d jzy3d added this to Higher Priority in Jzy3D May 24, 2022
@jzy3d jzy3d moved this from Higher Priority to Next version in Jzy3D May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Jzy3D
Next version
Development

Successfully merging a pull request may close this issue.

1 participant