Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Joakim Bygdell <joakim.bygdell@nbis.se>
  • Loading branch information
aaperis and jbygdell committed Feb 11, 2025
1 parent 3fec176 commit 518a823
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion sda/cmd/s3inbox/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ func (p *Proxy) allowedResponse(w http.ResponseWriter, r *http.Request, token jw
// The following block is for treating the case when the client loses connection to the server and then it reconnects to a
// different instance of s3inbox. For more details see #1358.
if p.fileIds[r.URL.Path] == "" {

p.fileIds[r.URL.Path], err = p.database.GetFileIDByUserPathAndStatus(username, filepath, "registered")
if err != nil {
p.internalServerError(w, r, fmt.Sprintf("failed to retrieve fileID from database: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion sda/internal/database/db_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (dbs *SDAdb) GetFileIDByUserPathAndStatus(submissionUser, filePath, status
// 2, 4, 8, 16, 32 seconds between each retry event.
for count := 1; count <= RetryTimes; count++ {
fileID, err = dbs.getFileIDByUserPathAndStatus(submissionUser, filePath, status)
if err == nil {
if err == nil || strings.Contains(err.Error(), "sql: no rows in result set") {
break
}
time.Sleep(time.Duration(math.Pow(2, float64(count))) * time.Second)
Expand Down
3 changes: 3 additions & 0 deletions sda/internal/database/db_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,9 @@ func (suite *DatabaseTests) TestGetFileIDByUserPathAndStatus() {
if err != nil {
suite.FailNow("Failed to register file")
}
// sanity check - shold fail
_, err = db.getFileIDByUserPathAndStatus("wrong-user", filePath, "registered")
assert.EqualError(suite.T(), err, "sql: no rows in result set")

// check happy path
fileID2, err := db.getFileIDByUserPathAndStatus(user, filePath, "registered")
Expand Down

0 comments on commit 518a823

Please sign in to comment.