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

gRPC Error causes No tests found #253

Closed
ethancadoo opened this issue Aug 16, 2022 · 31 comments · Fixed by #257
Closed

gRPC Error causes No tests found #253

ethancadoo opened this issue Aug 16, 2022 · 31 comments · Fixed by #257
Labels
wontfix This will not be worked on

Comments

@ethancadoo
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.

When trying to run the example case referenced in the README, I get the following error:

E/flutter (30883): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 51594, details: null, rawResponse: null, trailers: {})

Due to that error the manager application is never able to find the integration tests and so it perpetually displays "No tests found. This may because the information is not loaded.".

I do believe the manager is forming some kind of connection with the running client because pressing the button "Tap here to reload information" causes the client to perform a hot reload.

The client just displays a blank white screen.

To Reproduce
Steps to reproduce the behavior:

  1. Clone flutter_convient_test
  2. Open 2 separate terminal windows.
  3. In the first terminal window execute the following commands:
cd .\packages\convenient_test_manager\
flutter run -d windows --release
  1. In the second terminal execute the following commands:
cd .\packages\convenient_test\example\    
flutter run ./integration_test/main_test.dart --host-vmservice-port 9753 --disable-service-auth-codes --dart-define CONVENIENT_TEST_APP_CODE_DIR=$($PWD | select -Expand Path)

Expected behavior
A clear and concise description of what you expected to happen.

The manager application should find all the integration tests in the example and give the option to run the tests.

Screenshots
If applicable, add screenshots to help explain your problem.

2022-08-16 11_09_44-NVIDIA GeForce Overlay DT

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows
  • Version [e.g. 22] 11

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] Android Virtual Emulator - Pixel 4
  • OS: [e.g. iOS8.1] Android
  • Version [e.g. 22] API 30

Additional context
Add any other context about the problem here.

I tried to get around this issue by running the client within WSL ubuntu and trying to run the manager within WSL. Both result in the same error.
I also had a coworker try this on his Mac machine. He said the issue still occurs for him while using an Android Emulator but not when using the IOS simulator.
I have also tried this in our own repo instead of the example package, same error.
I also tried adjusting the values in consts.dart. I changed kConvenientTestManagerHost to my local IP address and still the same error. When I set kWorkerVmServiceHost to my local IP, I can no longer cause a hot reload in the client, so I believe that is a regression.

I have also read through pretty much every issue here: https://github.com/fzyzcjy/flutter_convenient_test/issues?q=is%3Aissue+grpc and still haven't found a solution. I know you mentioned in this comment that it was a generic network problem and not related to this package.

I realize from the error message this is definitely network related ("Error connecting: SocketException") but I do not believe my setup is in any way non-standard and a coworker was able to replicate the issue.

Could this be related to the fact that the Android Device Emulator defines the host machine on the constant address "10.0.2.2"? ref
I am not sure how one would point the client to that host because we are only passing a port in through the startup args. I am not sure if the IOS simulator on Mac redirects 127.0.0.1 to the simulator or the development machine.

By the way, thank you for such a great package! The design is great and is a wonderful contribution to the flutter ecosystem.

Manager Logs:

PS C:\Users\ethan\Documents\cadoo\flutter_convenient_test\packages\convenient_test_manager> flutter run -d windows --release
Launching lib\main.dart on Windows in release mode...
Building Windows application...                                         

Flutter run key commands.
h List all available interactive commands.
c Clear the screen
q Quit (terminate the application on the device).
flutter: 2022-08-16T15:08:12.832046Z|debug|GlobalConfigNullable|parseConfigFile homeDirectory=null
flutter: 2022-08-16T15:08:12.833048Z|debug|GlobalConfigNullable|parse call parseConfigFile config=GlobalConfigNullable(isolationMode: null, enableReportSaver: null, goldenDiffGitRepo: null)
flutter: 2022-08-16T15:08:12.833048Z|debug|GlobalConfigNullable|parse call parseEnvironment config=GlobalConfigNullable(isolationMode: null, enableReportSaver: null, goldenDiffGitRepo: null)
flutter: 2022-08-16T15:08:12.835043Z|info|VmServiceWrapperService|Connecting to vm service at ws://127.0.0.1:9753/ws. Please ensure your Flutter app has port=9753
flutter: 2022-08-16T15:08:12.836042Z|info|setup|GlobalConfig: isolationMode: false,[NL]enableReportSaver: false,[NL]goldenDiffGitRepo: null[NL]    
flutter: 2022-08-16T15:08:12.845042Z|debug|setWindowSize|window=PlatformWindow{frame: Rect.fromLTRB(17.0, 17.0, 2257.0, 1277.0), scaleFactor: 1.75, screen: Instance of 'Screen'} screen=Screen{frame: Rect.fromLTRB(0.0, 0.0, 3840.0, 2400.0), visibleFrame: Rect.fromLTRB(0.0, 0.0, 3840.0, 2316.0), scaleFactor: 1.75}
flutter: 2022-08-16T15:08:12.846040Z|info|GoldenDiffPageStore|syncGitInfoFromRepo gitRepo=null
flutter: 2022-08-16T15:08:14.884684Z|warn|VmServiceWrapperService|init failed e=SocketException: The remote computer refused the network connection.
flutter: [NL] (OS Error: The remote computer refused the network connection.
flutter: [NL], errno = 1225), address = 127.0.0.1, port = 57880 s=#0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:682)[NL]#1      _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1817)[NL]#2      RawSocket.startConnect (dart:io-patch/socket_patch.dart:27)[NL]#3      Socket._startConnect (dart:io-patch/socket_patch.dart:2038)[NL]#4      Socket.startConnect (dart:io/socket.dart:759)[NL]#5      _ConnectionTarget.connect (dart:_http/http_impl.dart:2453)[NL]#6      _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2867)[NL]#7      _HttpClient._getConnection (dart:_http/http_impl.dart:2872)[NL]#8      _HttpClient._openUrl (dart:_http/http_impl.dart:2727)[NL]#9      _HttpClient.openUrl (dart:_http/http_impl.dart:2591)[NL]#10     _WebSocketImpl.connect (dart:_http/we
flutter: bsocket_impl.dart:1021)[NL]#11     WebSocket.connect (dart:_http/websocket.dart:360)[NL]#12     vmServiceConnectUri (package:vm_service/vm_service_io.dart:32)[NL]#13     VmServiceWrapperService.connect (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:30)[NL]#14     new VmServiceWrapperService (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:20)[NL]#15     setup (package:convenient_test_manager_dart/misc/setup.dart:37)[NL]<asynchronous suspension>[NL]#16     setup (package:convenient_test_manager/misc/setup.dart:21)[NL]<asynchronous suspension>[NL]#17     main (package:convenient_test_manager/main.dart:7)[NL]<asynchronous suspension>[NL]       
flutter: 2022-08-16T15:09:29.585945Z|info|VmServiceWrapperService|Connecting to vm service at ws://127.0.0.1:9753/ws. Please ensure your Flutter app has port=9753
flutter: 2022-08-16T15:09:29.588943Z|info|_ServiceConnectionManager|vmServiceOpened
flutter: 2022-08-16T15:09:29.654944Z|info|_ServiceConnectionManager|handleServiceEvent kind=ServiceRegistered service=reloadSources method=s0.reloadSources
flutter: 2022-08-16T15:09:29.654944Z|info|_ServiceConnectionManager|handleServiceEvent kind=ServiceRegistered service=hotRestart method=s0.hotRestart
flutter: 2022-08-16T15:09:29.655948Z|info|_ServiceConnectionManager|handleServiceEvent kind=ServiceRegistered service=flutterVersion method=s0.flutterVersion
flutter: 2022-08-16T15:09:29.655948Z|info|_ServiceConnectionManager|handleServiceEvent kind=ServiceRegistered service=compileExpression method=s0.compileExpression
flutter: 2022-08-16T15:09:29.655948Z|info|_ServiceConnectionManager|handleServiceEvent kind=ServiceRegistered service=flutterMemoryInfo method=s0.flutterMemoryInfo
flutter: 2022-08-16T15:09:29.655948Z|info|_ServiceConnectionManager|handleServiceEvent kind=ServiceRegistered service=flutterGetSkSL method=s0.flutterGetSkSL
flutter: 2022-08-16T15:09:33.120960Z|info|VmServiceWrapperService|hotRestartThrottled triggered
flutter: 2022-08-16T15:09:33.120960Z|debug|SingleRunningExecutor|call runner() reason= triggerTime=2022-08-16 11:09:33.120960 arg=null
flutter: 2022-08-16T15:09:33.120960Z|info|_ServiceConnectionManager|hotRestart start
flutter: 2022-08-16T15:09:37.392235Z|info|_ServiceConnectionManager|hotRestart end resp={type: Success}
flutter: 2022-08-16T15:09:37.392235Z|debug|VmServiceWrapperService|hotRestartThrottledExecutor deliberately extra wait  
Application finished.
Terminate batch job (Y/N)? Y

Client Logs:

PS C:\Users\ethan\Documents\cadoo\flutter_convenient_test\packages\convenient_test\example> flutter run .\integration_test\main_test.dart --host-vmservice-port 9753 --disable-service-auth-codes --dart-define CONVENIENT_TEST_APP_CODE_DIR=$($PWD | select -Expand Path)
Using hardware rendering with device sdk gphone x86. If you notice graphics artifacts, consider enabling software      
rendering with "--enable-software-rendering".
Launching .\integration_test\main_test.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...                              5.5s
√  Built build\app\outputs\flutter-apk\app-debug.apk.
E/flutter (30883): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 51592, details: null, rawResponse: null, trailers: {})
E/flutter (30883):
Syncing files to device sdk gphone x86...                          218ms

Flutter run key commands.
r Hot reload.
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

 Running with sound null safety 

An Observatory debugger and profiler on sdk gphone x86 is available at: http://127.0.0.1:9753/
Performing hot restart...
Restarted application in 4,263ms.
E/flutter (30883): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 51594, details: null, rawResponse: null, trailers: {})
E/flutter (30883):
Application finished.
Terminate batch job (Y/N)? Y
@welcome
Copy link

welcome bot commented Aug 16, 2022

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 16, 2022

You are welcome!

Yes I think it is a network problem. Looks like your manager is connecting to localhost:9753:

flutter: 2022-08-16T15:08:12.835043Z|info|VmServiceWrapperService|Connecting to vm service at ws://127.0.0.1:9753/ws. Please ensure your Flutter app has port=9753

So maybe try to hack it to other IPs and see what happens.

Currently all things are hardcoded in source code:

const kConvenientTestManagerHost = '127.0.0.1';
const kConvenientTestManagerPort = 3579;

const kWorkerVmServiceHost = '127.0.0.1';
const kWorkerVmServicePort = 9753;

const kReportFileExtension = 'bin';

So need to clone the code and modify it, e.g. the kWorkerVmServiceHost.

@ethancadoo
Copy link
Contributor Author

ethancadoo commented Aug 16, 2022

Thank you for responding so quickly!
I believe that message isn't an error, it always happens every time the manager starts. (Please correct me if I am wrong).

Log.i(_kTag, 'Connecting to vm service at $uri. Please ensure your Flutter app has port=$kWorkerVmServicePort');

I know that the manager can access the client somewhat because it can cause a hot reload in the client. The problem seems to be communication from the client back to the manager.

I can also navigate to 127.0.0.1:9753 with my web browser and I see the following page:

2022-08-16 18_53_17-NVIDIA GeForce Overlay DT

I have tried changing the values in consts.dart with no success.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 16, 2022

You are welcome :)

I believe that message isn't an error, it always happens every time the manager starts. (Please correct me if I am wrong).

That log is not error. It just says where we are connecting.

I know that the manager can access the client somewhat because it can cause a hot reload in the client. The problem seems to be communication from the client back to the manager.

Oh I see, given the evidence so 127.0.0.1 maybe ok for the manager connecting to client.

So maybe change the ip from client to manager?

And, maybe try to connect to the specific host/port from client to manager. If it fails, we know it has problem

@ethancadoo
Copy link
Contributor Author

Ah gotcha, my bad with confusion around log message.

How would I go about changing the address that the client is using to connect to manager?

I know that in the android device emulator, 127.0.0.1 resolves to the virtual android device while 10.0.2.2 resolves to the local development machine. I am not sure that the IOS simulator works in the same.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 16, 2022

What about trying to change kConvenientTestManagerHost firstly, and maybe dig a bit into the code about grpc server/client creation code to see what arg is passed into it, if it does not work.

@ethancadoo
Copy link
Contributor Author

Solved by setting: kConvenientTestManagerHost to 10.0.2.2.

You were pretty much dead on from the beginning. I didn't realize that kConvenientTestManagerHost would effect the client plugin at all until I started going through the code. I thought that would only effect the manager side of things.

Every person using this within Android Device Emulator will hit this same problem. Maybe add something in the README stating this? Or it would be super cool if the plugin could dynamically detect this with https://pub.dev/packages/device_info_plus and switch dynamically. If you would use this I can make a PR.

Thanks again for the help @fzyzcjy!

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 17, 2022

You are welcome!

If you would use this I can make a PR.

Sure :) Looking forward to your PR!

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 17, 2022

dynamically detect this with https://pub.dev/packages/device_info_plus and switch dynamically

Not sure how this will be done? The current issue is that, the worker do not know the ip of master. But device info only tells the ip of worker imho

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 17, 2022

Maybe add something in the README stating this?

That LGTM :)

@ethancadoo
Copy link
Contributor Author

Maybe add something in the README stating this?

That LGTM :)

#257

@ethancadoo
Copy link
Contributor Author

You are welcome!

If you would use this I can make a PR.

Sure :) Looking forward to your PR!

Couldn't get everything working as I wanted perfectly because of the need for a widget binding, but created a starter branch here: #256

This was referenced Aug 18, 2022
@borjandev
Copy link

I am experiencing the same issue when attempting to use a physical device instead of a simulator (simulators work properly)

E/flutter (30720): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 47960, details: null, rawResponse: null, trailers: {})

I am using the latest master branches of the flutter_convenient_test

I tried changing using the CONVENIENT_TEST_MANAGER_HOST variable both on the client and the server to the local WIFI address of the physical device, but I still keep getting the same error and the address = 127.0.0.1 doesn't seem to be changing

I tried both with a Pixel 3 and an iPhone 12 Mini, both resulted in the same error

@fzyzcjy Have you used a physical device successfully before?

@ethancadoo Are you able to use a physical device?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Aug 30, 2022

@borjandev I have not played with a physical device yet, but definitely it should work given correct address.

CONVENIENT_TEST_MANAGER_HOST variable both on the client and the server to the local WIFI address of the physical device

That sound incorrect. "manager" is the desktop app, while "worker" is on the phone. So change WORKER_HOST

@ronba
Copy link
Contributor

ronba commented Sep 7, 2022

@borjandev this is what's working for me with the Android emulator - it would be similar to a wifi network as the emulator should connect via 10.0.2.2 .
@fzyzcjy / @ethancadoo if I'm doing something blatantly wrong would be awesome if you could jump in :)

Step 1:

You need to use the latest packages as that's where the override from environment variables is available.
Supply the following overrides on puspec.yaml:

dependency_overrides:
  convenient_test:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test
      path: packages/convenient_test
      ref: master
  convenient_test_common_dart:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test
      path: packages/convenient_test_common_dart
      ref: master

dependencies:

  convenient_test:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test
      path: packages/convenient_test
      ref: master

dev_dependencies:

  convenient_test_dev:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test
      path: packages/convenient_test_dev
      ref: master

Step 2

Run flutter:

flutter run integration_test/main_test.dart --host-vmservice-port 9753 --disable-service-auth-codes --dart-define CONVENIENT_TEST_MANAGER_HOST=10.0.2.2 --dart-define CONVENIENT_TEST_APP_CODE_DIR=$PWD -d "<your android emulator/physical device name>"

@ethancadoo
Copy link
Contributor Author

@ronba I believe that looks right. The command that works for me on windows with the android emulator is:

flutter run --flavor "development" --dart-define=ENV="dev"  integration_test/app_test.dart --host-vmservice-port 9753 --disable-service-auth-codes --dart-define=CONVENIENT_TEST_APP_CODE_DIR="$($PWD | select -Expand Path)" --dart-define=CONVENIENT_TEST_MANAGER_HOST="10.0.2.2"

And in different terminal I run:

cd ../
git clone https://github.com/fzyzcjy/flutter_convenient_test.git
cd flutter_convenient_test/packages/convenient_test_manager
git checkout -b master
git pull
flutter run -d windows --release --dart-define=CONVENIENT_TEST_ISOLATION_MODE=true

Are you able to see anything by navigating to "127.0.0.1:9753" in your web browser?
Are you on Mac? WSL for Windows? Linux?

My relevant section of the pubspec.yaml:

dependency_overrides:
  convenient_test_common:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test.git
      ref: master
      path: packages/convenient_test_common/
  convenient_test_common_dart:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test.git
      ref: master
      path: packages/convenient_test_common_dart/
  convenient_test:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test.git
      ref: master
      path: packages/convenient_test/
  convenient_test_dev:
    git:
      url: https://github.com/fzyzcjy/flutter_convenient_test.git
      ref: master
      path: packages/convenient_test_dev/

@bartekpacia
Copy link
Contributor

Any progress on this? It's really annoying :|

@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 20, 2022

@bartekpacia does the workaround mentioned above solve your problem?

@bartekpacia
Copy link
Contributor

bartekpacia commented Sep 20, 2022

I haven't tried, to be honest, but I'm sure it would. What I'm asking for is a bit more official solution, for example the possibility to set 10.0.2.2 in the Manager GUI directly (or detecting the OS automatically, as somebody mentioned above).

@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 20, 2022

Totally agree. Looking forward to your PR!

@bartekpacia
Copy link
Contributor

I'm surely submit something when I find some free time :)

@DanMossa
Copy link

Hey! I'm having this issue.

I'm using physical devices and the error happens on both iOS and Android.
I'm able to connect to http://127.0.0.1:9753/.

This is the command I'm running
flutter run /Users/daniel/app/integration_test/main_test.dart --host-vmservice-port 9753 --disable-service-auth-codes --dart-define CONVENIENT_TEST_APP_CODE_DIR=/Users/daniel/app

And the error I'm getting is

E/flutter (17346): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 39229, details: null, rawResponse: null, trailers: {})

@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 18, 2022

IIRC, physical devices cannot use 127.0.0.1

@DanMossa
Copy link

@fzyzcjy Ah, so how would I go about using this package to run integration tests on a physical device?

Thanks for the quick response by the way!

@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 19, 2022

@DanMossa That is unrelated to this package indeed, but a general grpc (or network?) question.

A quick guess: Say you are using wifi to connect phone and computer, and computer has 192.168.0.101 while phone has 192.168.0.102. Then maybe use those 192 ip instead of 127.0.0.1.

@DanMossa
Copy link

Sorry for all the questions, this is just new to me.
How can I find out what the IP of my computer or phone is?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 27, 2022

@DanMossa google it :) different computers (win mac linux) etc have different methods

@DanMossa
Copy link

@fzyzcjy Oh! I understand what you mean. I didn't realize. Okay perfect. Thank you!

@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 28, 2022

You are welcome!

@stale
Copy link

stale bot commented Dec 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Dec 28, 2022
@stale stale bot closed this as completed Jan 4, 2023
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix This will not be worked on
Projects
None yet
6 participants