Skip to content

Commit

Permalink
organize imports, simplify teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon committed Nov 8, 2023
1 parent b180f88 commit 453aacb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 6 additions & 5 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ func (a *sourcePluginAdapter) Stop(ctx context.Context, _ cpluginv1.SourceStopRe
}

func (a *sourcePluginAdapter) Teardown(ctx context.Context, _ cpluginv1.SourceTeardownRequest) (cpluginv1.SourceTeardownResponse, error) {
var waitErr error // store waitErr
err := a.state.DoWithLock(ctx, internal.DoWithLockOptions{
ExpectedStates: nil, // Teardown can be called from any state
StateBefore: internal.StateTearingDown,
Expand All @@ -344,6 +343,7 @@ func (a *sourcePluginAdapter) Teardown(ctx context.Context, _ cpluginv1.SourceTe
a.readCancel()
}

var waitErr error
if a.t != nil {
waitErr = a.waitForRun(ctx, teardownTimeout) // wait for Run to stop running
if waitErr != nil {
Expand All @@ -354,12 +354,13 @@ func (a *sourcePluginAdapter) Teardown(ctx context.Context, _ cpluginv1.SourceTe
}
}

return a.impl.Teardown(ctx)
err := a.impl.Teardown(ctx)
if err == nil {
err = waitErr
}
return err
})

if err == nil {
err = waitErr
}
return cpluginv1.SourceTeardownResponse{}, err
}

Expand Down
6 changes: 2 additions & 4 deletions source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import (
"testing"
"time"

"github.com/conduitio/conduit-connector-sdk/internal/cchan"

"github.com/conduitio/conduit-connector-sdk/internal"

"github.com/conduitio/conduit-connector-protocol/cpluginv1"
cpluginv1mock "github.com/conduitio/conduit-connector-protocol/cpluginv1/mock"
"github.com/conduitio/conduit-connector-sdk/internal"
"github.com/conduitio/conduit-connector-sdk/internal/cchan"
"github.com/golang/mock/gomock"
"github.com/matryer/is"
"github.com/rs/zerolog"
Expand Down

0 comments on commit 453aacb

Please sign in to comment.