Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing the library #23

Open
matejthetree opened this issue May 13, 2021 · 3 comments
Open

testing the library #23

matejthetree opened this issue May 13, 2021 · 3 comments

Comments

@matejthetree
Copy link

I am trying to write a test to check if the library works

void main() async {
  // WidgetsFlutterBinding.ensureInitialized();

  test('library works with primitives', () async {
    final isolates = IsolateHandler();

    var completer = Completer();
    // Set new count and display current count.
    void setCounter(int counter) {
      // We will no longer be needing the isolate, let's dispose of it.
      isolates.kill("counter");
      expectAsync0(() {
        expect(counter, 1);
      });
      completer.complete();
    }

    isolates.spawn<int>(entryPoint,
        name: "counter",
        // Executed every time data is received from the spawned isolate.
        onReceive: setCounter,
        // Executed once when spawned isolate is ready for communication.
        onInitialized: () => isolates.send(0, to: "counter"));

    await completer.future;
  });
}

void entryPoint(Map<String, dynamic> context) {
  // Calling initialize from the entry point with the context is
  // required if communication is desired. It returns a messenger which
  // allows listening and sending information to the main isolate.
  final messenger = HandledIsolate.initialize(context);

  // Triggered every time data is received from the main isolate.
  messenger.listen((req) {
    // Add one to the count and send the new value back to the main
    // isolate.
    if (req is int) {
      messenger.send(req++);
    }
  });
}

If I don't initialize widgets binding, I get
Null check operator used on a null value

package:flutter/src/services/platform_channel.dart 142:86  MethodChannel.binaryMessenger
package:flutter/src/services/platform_channel.dart 148:36  MethodChannel._invokeMethod
package:flutter/src/services/platform_channel.dart 331:12  MethodChannel.invokeMethod
package:flutter_isolate/flutter_isolate.dart 46:14         FlutterIsolate.spawn
package:isolate_handler/src/handled_isolate.dart 171:37    HandledIsolate._init
package:isolate_handler/src/handled_isolate.dart 99:5      new HandledIsolate
package:isolate_handler/isolate_handler.dart 178:22        IsolateHandler.spawn
test/src/util/isolate/isolate_handler_test.dart 25:14      main.<fn>
test/src/util/isolate/isolate_handler_test.dart 11:41      main.<fn>

And If I uncomment that line, I get
MissingPluginException(No implementation found for method spawn_isolate on channel com.rmawatson.flutterisolate/control)

How to run this library inside tests?

@matejthetree
Copy link
Author

any info on this one, still trying to test the implementation. hard to use in production, if plugin may break anytime with new versions.

@deakjahn
Copy link
Owner

No. I'm not an avid fan of such testing in cases like this (there are cases where things can be tested easily but I don't think this is one of them). If you can come up with a testing scenario that works and can be added, all right, but I'm unlikely to take any steps to add it myself. I'm not even sure a test environment works the same as the real one--don't forget, the main idea of flutter_isolate is to instantiate an extra Flutter engine in the first place.

@spysoos
Copy link

spysoos commented Dec 16, 2021

Same issue, but just in ios platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants