This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Conversation
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
jalextowle
force-pushed
the
test/browser-conversion-tests
branch
from
January 31, 2020 00:20
afeda41
to
f439ded
Compare
fabioberger
suggested changes
Feb 3, 2020
albrow
suggested changes
Feb 3, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I'm very impressed with this approach overall. It's clear you put a lot of thought and effort into it. There are a few small things I think we can improve.
jalextowle
force-pushed
the
test/browser-conversion-tests
branch
from
February 4, 2020 22:39
ede1f64
to
1b64f79
Compare
albrow
approved these changes
Feb 4, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with one small suggestion.
jalextowle
force-pushed
the
test/browser-conversion-tests
branch
from
February 5, 2020 02:06
6c98cbd
to
3331a95
Compare
fabioberger
approved these changes
Feb 5, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This pull request introduces a large addition to 0x-mesh's testing infrastructure. Tests were added that can effectively test the Go --> Typescript interface that is used to send data to Typescript code that would like to interact with a browser based mesh node. This interface was previously a source of lots of bugs and would have been difficult to maintain with manual code review alone.
Architecture
A new framework had to be created to test this interface properly. The crux of the issue in this test is that values must be converted to their javascript counterparts by Go code in a Wasm binary and then these values should be processed by real Javascript (or in this case Typescript) code. To accomplish this behavior, a new Wasm binary was created, and this binary is embedded in a testing script written in Typescript and then served to a browser that is running in a go-routine of another Go file that serves as the entry-point to the test. The next sections will more clearly outline the role of each component of the test.
Entry Point
The entry into these conversion tests is the file
browser/go/conversion-test/conversion_test.go
. This file has three primary responsibilities: register test cases; serve the bundled test logic; and scrape the logs created by the bundled test script to identify test passes and failures (and missing results).Registration of test cases is actually very straightforward. Test results are reported by the bundled test script in the form of console logs. These logs have a format of
$description: true
, wheretrue
indicates that the test passed. It is currently expected that these logs will be emitted in a particular order, so the test cases are registered in a slice calledtestCases
. The Go code that handles emitted logs from the headless browser will just iterate over the list oftestCases
and verify that there is a log that matches every entry oftestCases
. Some features were implemented that will identify some unexpected logs (we don't want to wait forever, so logs that come very late and aren't expected will not be identified). Additionally, all of the registration logic in this file is structured in such a way that most of the boilerplate writing can be avoided. If many more of these tests need to be written in the future, code generation could hypothetically create these registration functions from reading the typescript conversion test implementation (manual generation of tests should be totally sufficient for the foreseeable future).Typescript Conversion Test
Because of the way that Wasm currently works in the browser, the Typescript code in the bundle needs to control most of the testing inside of the browser. This code is responsible for instantiating a WebAssembly module that will execute the Wasm buffer and for verifying the results of calling test functions exposed by the Wasm code. The Wasm boilerplate is very similar to the implementation of
integration-tests/browser/src/index.ts
. When result are tested, logs are emitted that indicate whether or not an individual test passed or failed. There is a 1:1 correspondence between the logging calls in this file and the registration calls in the "entry point."Wasm Binary
The Wasm binary is responsible for providing functions that the Typescript Conversion test can use to receive data from Wasm. As of right now, all of these functions simply return
js.Value
conversions of all of the types that haveJSValue
methods; however, this will not necessarily be the case in the future.