-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into mempool_lock
- Loading branch information
Showing
12 changed files
with
153 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package stf | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// getExecutionCtxFromContext tries to get the execution context from the given go context. | ||
func getExecutionCtxFromContext(ctx context.Context) (*executionContext, error) { | ||
if ec, ok := ctx.(*executionContext); ok { | ||
return ec, nil | ||
} | ||
|
||
value, ok := ctx.Value(executionContextKey).(*executionContext) | ||
if ok { | ||
return value, nil | ||
} | ||
|
||
return nil, fmt.Errorf("failed to get executionContext from context") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package stf | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestGetExecutionCtxFromContext(t *testing.T) { | ||
t.Run("direct type *executionContext", func(t *testing.T) { | ||
ec := &executionContext{} | ||
result, err := getExecutionCtxFromContext(ec) | ||
if err != nil { | ||
t.Fatalf("expected no error, got %v", err) | ||
} | ||
if result != ec { | ||
t.Fatalf("expected %v, got %v", ec, result) | ||
} | ||
}) | ||
|
||
t.Run("context value of type *executionContext", func(t *testing.T) { | ||
ec := &executionContext{} | ||
ctx := context.WithValue(context.Background(), executionContextKey, ec) | ||
result, err := getExecutionCtxFromContext(ctx) | ||
if err != nil { | ||
t.Fatalf("expected no error, got %v", err) | ||
} | ||
if result != ec { | ||
t.Fatalf("expected %v, got %v", ec, result) | ||
} | ||
}) | ||
|
||
t.Run("invalid context type or value", func(t *testing.T) { | ||
ctx := context.Background() | ||
_, err := getExecutionCtxFromContext(ctx) | ||
if err == nil { | ||
t.Fatalf("expected error, got nil") | ||
} | ||
expectedErr := "failed to get executionContext from context" | ||
if err.Error() != expectedErr { | ||
t.Fatalf("expected error message %v, got %v", expectedErr, err.Error()) | ||
} | ||
}) | ||
} |