Run completes the configuration of test environment and starts the test server. T.Close should be called by the end of test to release any resources and shutdown the server. The parameter waitListeners specifies the amount of listeners the server is supposed to configure. Run() will block before a
(waitListeners int)
| 304 | // The parameter waitListeners specifies the amount of listeners the server is |
| 305 | // supposed to configure. Run() will block before all of them are up. |
| 306 | func (t *T) Run(waitListeners int) { |
| 307 | t.ensureCanRun() |
| 308 | cmd := t.buildCmd("run") |
| 309 | |
| 310 | // Capture maddy log and redirect it. |
| 311 | logOut, err := cmd.StderrPipe() |
| 312 | if err != nil { |
| 313 | t.Fatal("Test configuration failed:", err) |
| 314 | } |
| 315 | |
| 316 | t.Log("launching maddy", cmd.Args) |
| 317 | if err := cmd.Start(); err != nil { |
| 318 | t.Fatal("Test configuration failed:", err) |
| 319 | } |
| 320 | |
| 321 | serverStarted := make(chan bool) |
| 322 | |
| 323 | go func() { |
| 324 | defer close(serverStarted) |
| 325 | scnr := bufio.NewScanner(logOut) |
| 326 | for scnr.Scan() { |
| 327 | line := scnr.Text() |
| 328 | |
| 329 | t.Log("maddy:", line) |
| 330 | |
| 331 | if strings.HasPrefix(line, "server started") { |
| 332 | serverStarted <- true |
| 333 | } |
| 334 | |
| 335 | if strings.HasPrefix(line, "new server started") { |
| 336 | select { |
| 337 | case t.reloadedChan <- struct{}{}: |
| 338 | t.Log("server reload confirmed, continuing test") |
| 339 | default: |
| 340 | t.Log("unexpected reloads detected") |
| 341 | t.Fail() |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | if err := scnr.Err(); err != nil { |
| 346 | t.Log("stderr I/O error:", err) |
| 347 | } |
| 348 | }() |
| 349 | |
| 350 | if !<-serverStarted { |
| 351 | t.Fatal("Log ended before all expected listeners are up. Start-up error?") |
| 352 | } |
| 353 | |
| 354 | t.servProc = cmd |
| 355 | |
| 356 | t.Cleanup(t.killServer) |
| 357 | } |
| 358 | |
| 359 | func (t *T) StateDir() string { |
| 360 | return filepath.Join(t.testDir, "statedir") |