-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #635 from ericchiang/dev-transaction-tests
storage/conformance: add tests for transactional guarantees
- Loading branch information
Showing
4 changed files
with
106 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// +build go1.7 | ||
|
||
package conformance | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/coreos/dex/storage" | ||
) | ||
|
||
// RunTransactionTests runs a test suite aimed a verifying the transaction | ||
// guarantees of the storage interface. Atomic updates, deletes, etc. The | ||
// storage returned by newStorage will be closed at the end of each test run. | ||
// | ||
// This call is separate from RunTests because some storage perform extremely | ||
// poorly under deadlocks, such as SQLite3, while others may be working towards | ||
// conformance. | ||
func RunTransactionTests(t *testing.T, newStorage func() storage.Storage) { | ||
runTests(t, newStorage, []subTest{ | ||
{"ClientConcurrentUpdate", testClientConcurrentUpdate}, | ||
}) | ||
} | ||
|
||
func testClientConcurrentUpdate(t *testing.T, s storage.Storage) { | ||
c := storage.Client{ | ||
ID: storage.NewID(), | ||
Secret: "foobar", | ||
RedirectURIs: []string{"foo://bar.com/", "https://auth.example.com"}, | ||
Name: "dex client", | ||
LogoURL: "https://goo.gl/JIyzIC", | ||
} | ||
|
||
if err := s.CreateClient(c); err != nil { | ||
t.Fatalf("create client: %v", err) | ||
} | ||
|
||
var err1, err2 error | ||
|
||
err1 = s.UpdateClient(c.ID, func(old storage.Client) (storage.Client, error) { | ||
old.Secret = "new secret 1" | ||
err2 = s.UpdateClient(c.ID, func(old storage.Client) (storage.Client, error) { | ||
old.Secret = "new secret 2" | ||
return old, nil | ||
}) | ||
return old, nil | ||
}) | ||
|
||
t.Logf("update1: %v", err1) | ||
t.Logf("update2: %v", err2) | ||
|
||
if err1 == nil && err2 == nil { | ||
t.Errorf("update client: concurrent updates both returned no error") | ||
} | ||
} |
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