Skip to content

Commit

Permalink
add ctx to handlers.Wait
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch-spike committed Feb 27, 2024
1 parent e306436 commit a876ab5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions backup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package backuplib

import (
"context"
"io"

"github.com/aerospike/aerospike-tools-backup-lib/encoding/asb"
Expand Down Expand Up @@ -167,8 +168,13 @@ func (bwh *BackupHandler) GetStats() BackupStatus {
}

// Wait waits for the backup job to complete and returns an error if the job failed
func (bwh *BackupHandler) Wait() error {
return <-bwh.errors
func (bwh *BackupHandler) Wait(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
case err := <-bwh.errors:
return err
}
}

func getDataWriter(eb EncoderBuilder, w io.Writer, namespace string, first bool) (*WriteWorker[*models.Token], error) {
Expand Down
6 changes: 4 additions & 2 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package backuplib_test

import (
"bytes"
"context"
"fmt"
"io"
"testing"
Expand Down Expand Up @@ -178,7 +179,8 @@ func (suite *backupRestoreTestSuite) TestBackupRestoreIO() {
suite.Nil(err)
suite.NotNil(bh)

err = bh.Wait()
ctx := context.Background()
err = bh.Wait(ctx)
suite.Nil(err)

err = suite.testClient.Truncate(namespace, set)
Expand All @@ -195,7 +197,7 @@ func (suite *backupRestoreTestSuite) TestBackupRestoreIO() {
suite.Nil(err)
suite.NotNil(rh)

err = rh.Wait()
err = rh.Wait(ctx)
suite.Nil(err)

err = suite.testClient.ValidateRecords(expectedRecs, numRec, namespace, set)
Expand Down
10 changes: 8 additions & 2 deletions restore_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package backuplib

import (
"context"
"io"

"github.com/aerospike/aerospike-tools-backup-lib/models"
Expand Down Expand Up @@ -161,6 +162,11 @@ func (rrh *RestoreHandler) GetStats() RestoreStatus {
}

// Wait waits for the restore job to complete and returns an error if the job failed
func (rrh *RestoreHandler) Wait() error {
return <-rrh.errors
func (rrh *RestoreHandler) Wait(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
case err := <-rrh.errors:
return err
}
}

0 comments on commit a876ab5

Please sign in to comment.