mirror of https://github.com/casbin/casnode.git
Improve error handling for TestSyncAvatars().
This commit is contained in:
parent
1b511f62d1
commit
3fcf1c444b
|
@ -16,6 +16,7 @@ package casdoor
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/casdoor/casdoor-go-sdk/auth"
|
||||
"xorm.io/core"
|
||||
|
@ -207,7 +208,8 @@ func UpdateUser(owner string, name string, user *auth.User) bool {
|
|||
affected, err = updateUser(owner, name, user)
|
||||
if err != nil {
|
||||
times += 1
|
||||
if times >= 5 {
|
||||
time.Sleep(3 * time.Second)
|
||||
if times >= 10 {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -95,7 +95,11 @@ func syncAvatarForUser(user *auth.User) string {
|
|||
}
|
||||
}
|
||||
|
||||
avatarUrl := uploadDiscuzxAvatar(username, fileBytes, fileExt)
|
||||
avatarUrl, err := uploadDiscuzxAvatar(username, fileBytes, fileExt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return avatarUrl
|
||||
}
|
||||
|
||||
|
@ -126,6 +130,10 @@ func updateDefaultAvatarForUser(user *auth.User) string {
|
|||
|
||||
fileExt = path.Ext(newUrl)
|
||||
|
||||
avatarUrl := uploadDiscuzxAvatar(username, fileBytes, fileExt)
|
||||
avatarUrl, err := uploadDiscuzxAvatar(username, fileBytes, fileExt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return avatarUrl
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"github.com/casdoor/casdoor-go-sdk/auth"
|
||||
)
|
||||
|
||||
var SyncAvatarsConcurrency = 50
|
||||
var SyncAvatarsConcurrency = 20
|
||||
|
||||
func TestSyncAvatars(t *testing.T) {
|
||||
object.InitConfig()
|
||||
|
|
|
@ -26,11 +26,11 @@ import (
|
|||
"github.com/casbin/casnode/service"
|
||||
)
|
||||
|
||||
func uploadDiscuzxAvatar(username string, fileBytes []byte, fileExt string) string {
|
||||
func uploadDiscuzxAvatar(username string, fileBytes []byte, fileExt string) (string, error) {
|
||||
username = url.QueryEscape(username)
|
||||
memberId := fmt.Sprintf("%s/%s", CasdoorOrganization, username)
|
||||
fileUrl, _ := service.UploadFileToStorageSafe(memberId, "avatar", "uploadDiscuzxAvatar", fmt.Sprintf("avatar/%s%s", memberId, fileExt), fileBytes, "", "")
|
||||
return fileUrl
|
||||
fileUrl, err := service.UploadFileToStorageSafe(memberId, "avatar", "uploadDiscuzxAvatar", fmt.Sprintf("avatar/%s%s", memberId, fileExt), fileBytes, "", "")
|
||||
return fileUrl, err
|
||||
}
|
||||
|
||||
func convertImageToPng(imageBytes []byte) ([]byte, string, error) {
|
||||
|
|
|
@ -99,7 +99,8 @@ func getRedirectUrl(url string) string {
|
|||
_, err = client.Do(req)
|
||||
if err != nil {
|
||||
times += 1
|
||||
if times >= 5 {
|
||||
time.Sleep(3 * time.Second)
|
||||
if times >= 10 {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -14,7 +14,11 @@
|
|||
|
||||
package service
|
||||
|
||||
import "github.com/casdoor/casdoor-go-sdk/auth"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/casdoor/casdoor-go-sdk/auth"
|
||||
)
|
||||
|
||||
// UploadFileToStorage uploads a file to the path, returns public URL
|
||||
func UploadFileToStorage(user string, tag string, parent string, fullFilePath string, fileBytes []byte) (string, error) {
|
||||
|
@ -30,7 +34,8 @@ func UploadFileToStorageSafe(user string, tag string, parent string, fullFilePat
|
|||
fileUrl, _, err = auth.UploadResourceEx(user, tag, parent, fullFilePath, fileBytes, createdTime, description)
|
||||
if err != nil {
|
||||
times += 1
|
||||
if times >= 5 {
|
||||
time.Sleep(3 * time.Second)
|
||||
if times >= 10 {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue