Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from mozilla-services/stability-fixes
database: error instead of dying on monitor failure
- Loading branch information
Showing
11 changed files
with
334 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package database | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestMonitor(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("runs and dies on connection close", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
// connects | ||
db, err := Connect(Config{ | ||
Name: "autograph", | ||
User: "myautographdbuser", | ||
Password: "myautographdbpassword", | ||
Host: "127.0.0.1:5432", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
quit := make(chan bool) | ||
go db.Monitor(5*time.Millisecond, quit) | ||
|
||
// should not error for initial monitor run | ||
err = db.CheckConnection() | ||
if err != nil { | ||
t.Fatalf("db.CheckConnection failed when it should not have with error: %s", err) | ||
} | ||
time.Sleep(10 * time.Millisecond) | ||
|
||
// error for failing checks | ||
db.Close() | ||
err = db.CheckConnection() | ||
if err == nil { | ||
t.Fatalf("db.CheckConnection did not fail for a closed DB") | ||
} | ||
|
||
quit <- true | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.