-
Notifications
You must be signed in to change notification settings - Fork 8
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 #68 from olachat/yinloo/support-retry
support retry
- Loading branch information
Showing
4 changed files
with
195 additions
and
7 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,33 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/olachat/gola/v2/coredb" | ||
) | ||
|
||
func TestExecWithRetry_Success(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
_, err := coredb.ExecWithRetry(ctx, testDBName, "INSERT INTO test_table (name, email) VALUES (?, ?)", coredb.DefaultRetryConfig, "test", "[email protected]") | ||
if err != nil { | ||
t.Fatalf("Expected success, but got error: %v", err) | ||
} | ||
} | ||
|
||
func TestExecWithRetry_Fail(t *testing.T) { | ||
ctx := context.Background() | ||
now := time.Now() | ||
_, err := coredb.ExecWithRetry(ctx, testDBName, "INSERT INTO no_such_table (name, email) VALUES (?, ?)", coredb.DefaultRetryConfig, "test", "[email protected]") | ||
if err == nil { | ||
t.Fatalf("Expected error, but got success") | ||
} | ||
elapsed := time.Since(now) | ||
if elapsed < (200+400+800+1600+3200)*time.Millisecond { | ||
t.Fatalf("Expected retry to take at least 100ms, but took: %v", elapsed) | ||
} | ||
t.Logf("retry took: %v", elapsed) | ||
} |
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