Bulk lazy initialization of FunctionDefinitions (#1425)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com> Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
"github.com/tetratelabs/wazero/internal/testing/hammer"
|
||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||
)
|
||||
|
||||
@@ -253,7 +254,25 @@ func TestModule_BuildFunctionDefinitions(t *testing.T) {
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.m.BuildFunctionDefinitions()
|
||||
tc.m.buildFunctionDefinitions()
|
||||
require.Equal(t, tc.expected, tc.m.FunctionDefinitionSection)
|
||||
require.Equal(t, tc.expectedImports, tc.m.ImportedFunctions())
|
||||
require.Equal(t, tc.expectedExports, tc.m.ExportedFunctions())
|
||||
})
|
||||
}
|
||||
|
||||
// Execute the same tests with n=`concurrentCount` goroutines invoking `buildFunctionDefinitions()` at once.
|
||||
const nGoroutines = 100
|
||||
const nIterations = 10
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
testName := tc.name + " (concurrent)"
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
hammer.NewHammer(t, nGoroutines, nIterations).
|
||||
Run(func(name string) {
|
||||
tc.m.buildFunctionDefinitions()
|
||||
}, nil)
|
||||
|
||||
require.Equal(t, tc.expected, tc.m.FunctionDefinitionSection)
|
||||
require.Equal(t, tc.expectedImports, tc.m.ImportedFunctions())
|
||||
require.Equal(t, tc.expectedExports, tc.m.ExportedFunctions())
|
||||
|
||||
Reference in New Issue
Block a user