From 47792608ceac59a95527f914e2a44e8d34ae0d76 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Thu, 4 Nov 2021 14:10:32 +0100 Subject: [PATCH] openvidu-test-e2e: protect dispose method @AfterEach from possible NullPointer --- .../e2e/AbstractOpenViduTestAppE2eTest.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestAppE2eTest.java b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestAppE2eTest.java index 7cc032ff..d7798462 100644 --- a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestAppE2eTest.java +++ b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestAppE2eTest.java @@ -392,37 +392,41 @@ public class AbstractOpenViduTestAppE2eTest { @AfterEach protected void dispose() { + // Close all remaining OpenVidu sessions this.closeAllSessions(OV); + // Remove all recordings if (isRecordingTest) { deleteAllRecordings(OV); isRecordingTest = false; } + // Reset Media Server if (isKurentoRestartTest) { this.stopMediaServer(false); this.startMediaServer(true); isKurentoRestartTest = false; } + // Dispose all browsers Iterator it = users.iterator(); while (it.hasNext()) { MyUser u = it.next(); u.dispose(); it.remove(); } - if (chrome.isRunning()) { - chrome.stop(); - } - if (firefox.isRunning()) { - firefox.stop(); - } - if (opera.isRunning()) { - opera.stop(); - } - if (edge.isRunning()) { - edge.stop(); - } + // Stop and remove all browser containers if necessary + stopContainerIfPossible(chrome); + stopContainerIfPossible(firefox); + stopContainerIfPossible(opera); + stopContainerIfPossible(edge); + // Reset REST client OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET); } + private void stopContainerIfPossible(GenericContainer container) { + if (container != null && container.isRunning()) { + container.stop(); + } + } + protected void closeAllSessions(OpenVidu client) { try { client.fetch();