From c285339cd9cdf944c74bde51a9e2b7392d3c077e Mon Sep 17 00:00:00 2001
From: dabund24 <dabund24@gmail.com>
Date: Fri, 7 Feb 2025 23:59:12 +0100
Subject: [PATCH] prevent timeouts in dbweb e2e test from calling `end()` twice

---
 test/e2e/dbweb.js | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/test/e2e/dbweb.js b/test/e2e/dbweb.js
index 70c81290..07361820 100644
--- a/test/e2e/dbweb.js
+++ b/test/e2e/dbweb.js
@@ -395,16 +395,17 @@ tap.test('trip details', async (t) => {
 });
 
 tap.test('departures at Berlin Schwedter Str.', async (t) => {
-	const interval = setInterval(async () => {
+	let interval = setInterval(async () => {
 		const res = await client.departures(blnSchwedterStr, {
 			duration: 5, when,
 		});
 
-		if (res.departures[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
+		if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
 			return;
 		}
 
 		clearInterval(interval);
+		interval = undefined;
 		await testDepartures({
 			test: t,
 			res,
@@ -416,7 +417,7 @@ tap.test('departures at Berlin Schwedter Str.', async (t) => {
 });
 
 tap.test('departures with station object', async (t) => {
-	const interval = setInterval(async () => {
+	let interval = setInterval(async () => {
 		const res = await client.departures({
 			type: 'station',
 			id: jungfernheide,
@@ -428,11 +429,12 @@ tap.test('departures with station object', async (t) => {
 			},
 		}, {when});
 
-		if (res.departures[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
+		if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
 			return;
 		}
 
 		clearInterval(interval);
+		interval = undefined;
 		validate(t, res, 'departuresResponse', 'res');
 		t.end();
 
@@ -440,16 +442,17 @@ tap.test('departures with station object', async (t) => {
 });
 
 tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
-	const interval = setInterval(async () => {
+	let interval = setInterval(async () => {
 		const res = await client.arrivals(blnSchwedterStr, {
 			duration: 5, when,
 		});
 
-		if (res.arrivals[0].stop.name === undefined) { // ctx.common.locations have not loaded yet
+		if (res.arrivals[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
 			return;
 		}
 
 		clearInterval(interval);
+		interval = undefined;
 		await testArrivals({
 			test: t,
 			res,