-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(go): make Load call idempotent (#2645)
Making the `Load` runtime library call idempotent makes it so that the `Client` can be fully disposed (via the `Close` call), while subsequently getting a new client starte up if needed. This is in particular useful for implementing test suites that operate on a clean kernel instance each time. This entails making sure the registered type information (as in the `typeregistry.TypeRegistry` instance) survives `*Client.Close()`, as the `init` functions will not re-trigger. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information
1 parent
f4a1468
commit d6140ce
Showing
12 changed files
with
198 additions
and
149 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
41 changes: 36 additions & 5 deletions
41
packages/@jsii/go-runtime/jsii-runtime-go/internal/kernel/client_test.go
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 |
---|---|---|
@@ -1,30 +1,61 @@ | ||
package kernel | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/jsii-runtime-go/internal/typeregistry" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestClient(t *testing.T) { | ||
client, err := newClient() | ||
if err != nil { | ||
t.Log(err) | ||
panic(fmt.Sprintf("Client init error: %s", err.Error())) | ||
t.Fatalf("client init failed: %s", err.Error()) | ||
} | ||
defer client.close() | ||
|
||
t.Run("Client Load Error", func(t *testing.T) { | ||
request := LoadProps{ | ||
Name: "jsii-calc", | ||
Version: "0.0.0", | ||
Tarball: "jsii-calc-tarball.tgz", | ||
} | ||
|
||
res, err := client.Load(request) | ||
res, err := client.Load(request, nil) | ||
|
||
t.Log(res) | ||
if err != nil { | ||
t.Log(err) | ||
} | ||
}) | ||
|
||
t.Run("Type registry survives CloseClient()", func(t *testing.T) { | ||
client, err := newClient() | ||
if err != nil { | ||
t.Fatalf("client init failed: %s", err.Error()) | ||
} | ||
|
||
// Clean up after ourselves, so this test does not leave traces behind. | ||
defer func() { types = typeregistry.New() }() | ||
|
||
type enumType string | ||
var enumTypeFOO enumType = "FOO" | ||
|
||
registry := client.Types() | ||
err = registry.RegisterEnum( | ||
"example.Enum", | ||
reflect.TypeOf((*enumType)(nil)).Elem(), | ||
map[string]interface{}{"FOO": enumTypeFOO}, | ||
) | ||
if err != nil { | ||
t.Fatalf("failed registering enum: %s", err.Error()) | ||
} | ||
|
||
CloseClient() | ||
|
||
// Getting the registry from the client again. | ||
registry = client.Types() | ||
|
||
if _, ok := registry.TryRenderEnumRef(reflect.ValueOf(enumTypeFOO)); !ok { | ||
t.Errorf("failed rendering enum ref, it should have worked!") | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.