Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
NodeDelete needs to be asynchronous
Browse files Browse the repository at this point in the history
NodeDelete was returning StatusOK, when in fact it should be
returning StatusAccepted so that the work is done asynchronously.

Closes #116

Signed-off-by: Luis Pabón <lpabon@redhat.com>
  • Loading branch information
Luis Pabón committed Aug 7, 2015
1 parent ce40304 commit fd68452
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 6 additions & 5 deletions apps/glusterfs/app_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ func (a *App) NodeDelete(w http.ResponseWriter, r *http.Request) {
return
}

// Show that the key has been deleted
logger.Info("Deleted node [%s]", id)

// Write msg
w.WriteHeader(http.StatusOK)
a.asyncManager.AsyncHttpRedirectFunc(w, r, func() (string, error) {
time.Sleep(1 * time.Second)
// Show that the key has been deleted
logger.Info("Deleted node [%s]", id)
return "", nil
})
}
18 changes: 17 additions & 1 deletion apps/glusterfs/app_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,23 @@ func TestNodeAddDelete(t *testing.T) {
tests.Assert(t, err == nil)
r, err = http.DefaultClient.Do(req)
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusOK)
tests.Assert(t, r.StatusCode == http.StatusAccepted)
location, err = r.Location()
tests.Assert(t, err == nil)

// Wait for deletion
for {
r, err := http.Get(location.String())
tests.Assert(t, err == nil)
if r.Header.Get("X-Pending") == "true" {
tests.Assert(t, r.StatusCode == http.StatusOK)
time.Sleep(time.Millisecond * 10)
continue
} else {
tests.Assert(t, r.StatusCode == http.StatusNoContent)
break
}
}

// Check db to make sure key is removed
err = app.db.View(func(tx *bolt.Tx) error {
Expand Down

0 comments on commit fd68452

Please sign in to comment.