From adc672003156b34026a0c84253935f0e476adae5 Mon Sep 17 00:00:00 2001
From: Martin Geisler <mgeisler@google.com>
Date: Wed, 1 Mar 2023 11:54:28 +0100
Subject: [PATCH] Increase playground timeout to 15 seconds

We often see timeouts when running the course. Most of the time, the
code compiles on the second try, which indicates that we just need to
wait a little longer.

Fixes #406.
---
 ga4.js                     | 7 ++++---
 third_party/mdbook/book.js | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ga4.js b/ga4.js
index b075cdb1..4f7dd63a 100644
--- a/ga4.js
+++ b/ga4.js
@@ -43,9 +43,10 @@ window.fetch = async (...args) => {
   const startTime = window.performance.now();
   let endTime, errorMessage;
   try {
-    // The fetch_with_timeout function defaults to a 6000 ms timeout. We use a
-    // slightly shorter timeout so that we can catch and log the error.
-    config.signal = AbortSignal.timeout(5500);
+    // The fetch_with_timeout function from book.js defaults to a 15000 ms
+    // timeout. We use a slightly shorter timeout so that we can catch and log
+    // the error.
+    config.signal = AbortSignal.timeout(14500);
     let response = await originalFetch(resource, config);
     payload = await response.json();
     errorMessage = (payload.error == null) ? null : 'compilation_error';
diff --git a/third_party/mdbook/book.js b/third_party/mdbook/book.js
index e303ebb4..11099d9d 100644
--- a/third_party/mdbook/book.js
+++ b/third_party/mdbook/book.js
@@ -18,7 +18,7 @@ function playground_text(playground, hidden = true) {
 }
 
 (function codeSnippets() {
-    function fetch_with_timeout(url, options, timeout = 6000) {
+    function fetch_with_timeout(url, options, timeout = 15000) {
         return Promise.race([
             fetch(url, options),
             new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout))