Skip to content

Commit faad38b

Browse files
committed
test: bound the HSQLDB boot poll and keep its runtime log for failures
1 parent 101e4b2 commit faad38b

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎cmd/mxcli/docker/runlocal_hsqldb_integration_test.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package docker
66

77
import (
8+
"bytes"
89
"io"
910
"net/http"
1011
"os"
@@ -70,6 +71,7 @@ func TestRunLocal_HSQLDBNeedsNoDatabaseServer(t *testing.T) {
7071
}
7172

7273
deployDir := filepath.Join(filepath.Dir(mprPath), "deployment")
74+
var rtOut bytes.Buffer
7375
rt, err := StartLocalRuntime(LocalRuntimeOptions{
7476
DeployDir: deployDir,
7577
InstallPath: installPath,
@@ -78,25 +80,26 @@ func TestRunLocal_HSQLDBNeedsNoDatabaseServer(t *testing.T) {
7880
AppPort: 8087,
7981
AdminPort: 8097,
8082
DB: DBConfig{Type: "HSQLDB", Name: deriveDBName(mprPath)},
81-
Stdout: io.Discard,
82-
Stderr: io.Discard,
83+
Stdout: &rtOut,
84+
Stderr: &rtOut,
8385
})
8486
if err != nil {
8587
t.Fatalf("boot with the built-in database: %v", err)
8688
}
8789
defer rt.Stop()
8890

91+
client := &http.Client{Timeout: 5 * time.Second}
8992
deadline := time.Now().Add(90 * time.Second)
9093
for {
91-
resp, err := http.Get(rt.AppURL())
94+
resp, err := client.Get(rt.AppURL())
9295
if err == nil {
9396
resp.Body.Close()
9497
if resp.StatusCode == 200 {
9598
break
9699
}
97100
}
98101
if time.Now().After(deadline) {
99-
t.Fatalf("app did not answer 200 at %s", rt.AppURL())
102+
t.Fatalf("app did not answer 200 at %s\n--- runtime output ---\n%s", rt.AppURL(), rt.Log())
100103
}
101104
time.Sleep(time.Second)
102105
}

‎cmd/mxcli/docker/runtime_controller.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (c *RuntimeController) Start() (*M2EEResponse, error) {
9494
if err != nil {
9595
return nil, err
9696
}
97+
schemaAttempted := false
9798
if needsDBUpdate(resp) {
9899
ddl, err := CallM2EE(c.opts, "execute_ddl_commands", nil)
99100
if err != nil {
@@ -102,12 +103,16 @@ func (c *RuntimeController) Start() (*M2EEResponse, error) {
102103
if msg := ddl.M2EEError(); msg != "" {
103104
return nil, fmt.Errorf("execute_ddl_commands failed: %s", msg)
104105
}
106+
schemaAttempted = true
105107
resp, err = CallM2EE(c.opts, "start", nil)
106108
if err != nil {
107109
return nil, err
108110
}
109111
}
110112
if msg := resp.M2EEError(); msg != "" {
113+
if schemaAttempted {
114+
return resp, fmt.Errorf("start failed after creating or updating the database schema: %s", msg)
115+
}
111116
return resp, fmt.Errorf("start failed: %s", msg)
112117
}
113118
// The runtime is up; wire the application log to a file (best-effort — a
@@ -214,6 +219,9 @@ func (c *RuntimeController) ApplyBuild(build *BuildResult, restart func() error)
214219
// all. This is the normal first boot of the built-in HSQLDB database, whose
215220
// JDBC URL carries ifexists=true and therefore never creates the file.
216221
//
222+
// Measured on Mendix 11.12.2: a fresh built-in HSQLDB project answers start
223+
// with Result 2 and Message "The database to be used does not exist.".
224+
//
217225
// The synchronizationreason feedback is a third signal the runtime sometimes
218226
// sends instead of the message.
219227
func needsDBUpdate(resp *M2EEResponse) bool {

0 commit comments

Comments
 (0)