openvidu-test-e2e: protect dispose method @AfterEach from possible NullPointer

pull/664/head
pabloFuente 2021-11-04 14:10:32 +01:00
parent 3baa72396f
commit 47792608ce
1 changed files with 16 additions and 12 deletions

View File

@ -392,37 +392,41 @@ public class AbstractOpenViduTestAppE2eTest {
@AfterEach @AfterEach
protected void dispose() { protected void dispose() {
// Close all remaining OpenVidu sessions
this.closeAllSessions(OV); this.closeAllSessions(OV);
// Remove all recordings
if (isRecordingTest) { if (isRecordingTest) {
deleteAllRecordings(OV); deleteAllRecordings(OV);
isRecordingTest = false; isRecordingTest = false;
} }
// Reset Media Server
if (isKurentoRestartTest) { if (isKurentoRestartTest) {
this.stopMediaServer(false); this.stopMediaServer(false);
this.startMediaServer(true); this.startMediaServer(true);
isKurentoRestartTest = false; isKurentoRestartTest = false;
} }
// Dispose all browsers
Iterator<MyUser> it = users.iterator(); Iterator<MyUser> it = users.iterator();
while (it.hasNext()) { while (it.hasNext()) {
MyUser u = it.next(); MyUser u = it.next();
u.dispose(); u.dispose();
it.remove(); it.remove();
} }
if (chrome.isRunning()) { // Stop and remove all browser containers if necessary
chrome.stop(); stopContainerIfPossible(chrome);
} stopContainerIfPossible(firefox);
if (firefox.isRunning()) { stopContainerIfPossible(opera);
firefox.stop(); stopContainerIfPossible(edge);
} // Reset REST client
if (opera.isRunning()) {
opera.stop();
}
if (edge.isRunning()) {
edge.stop();
}
OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET); OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
} }
private void stopContainerIfPossible(GenericContainer<?> container) {
if (container != null && container.isRunning()) {
container.stop();
}
}
protected void closeAllSessions(OpenVidu client) { protected void closeAllSessions(OpenVidu client) {
try { try {
client.fetch(); client.fetch();