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

CocoonService uses relative domain for API on web #522

Merged
merged 13 commits into from
Nov 8, 2019

Conversation

CaseyHillers
Copy link
Contributor

@CaseyHillers CaseyHillers commented Nov 7, 2019

Closes flutter/flutter#43103

Allows for using production data on AppEngine versions that are not in production. Additionally, allows for use of local dart server.

Open questions

  • Is there a better way of building the URL? I think it is unnecessary to include the endpoint twice, but my only idea is to move it to a separate variable.

@CaseyHillers CaseyHillers changed the title [WIP] Cocoon uses relative domain for API, TaskOverlay duration fix CocoonService uses relative domain for API on web Nov 7, 2019
Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test?

@CaseyHillers
Copy link
Contributor Author

@jonahwilliams is there a way to configure the kIsWeb constant in tests? Right now my approach would be to test for whatever the test framework defaults to, but that doesn't test the other case.

@jonahwilliams
Copy link
Member

You can also run tests with flutter test --platform=chrome. Then in the test case, use kIsWeb to determine what you're looking for

final String getStatusUrl = kIsWeb
? '/api/public/get-status'
: '$_baseApiUrl/api/public/get-status';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider encapsulate this pattern into a function, so that this pattern isn't scattered in 3 functions. For example,

// This function helps the Web app talks to a local Cocoon AppEngine instance when running locally, or talks to 
// the production instance when deployed into production.
// The urlSuffix begins with a slash, e.g. "/api/public/get-status".
String getEndpoint(String urlSuffix) {
  return kIsWeb ? urlSuffix : 'https://flutter-dashboard.appspot.com$urlSuffix;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Added.

@CaseyHillers
Copy link
Contributor Author

Should I report differences in the platform tests?

--platform=chrome does not throw NetworkImageLoadException for a NetworkImage widget when it is expected to. Instead it throws null.

For now, I can just have Cirrus run this platform test on this particular test.

@CaseyHillers
Copy link
Contributor Author

@jonahwilliams I added tests and added the chrome test for Cirrus. Currently only runs this group of tests as there are some failures.

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonahwilliams
Copy link
Member

Can you file an issue for the lack of the network exception on the web?

@CaseyHillers
Copy link
Contributor Author

Of course! Do you know if there is a best practice for installing google-chrome on Cirrus?

I noticed flutter/flutter just installs it in the Dockerfile https://github.com/flutter/flutter/blob/master/dev/ci/docker_linux/Dockerfile

/// before falling back to the production endpoint.
///
/// This function helps the Web app talks to the Cocoon service relative to
/// where it's running. On mobile, default to use the production
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain the magic: "On Web, a relative url automatically resolves to a local Cocoon instance when available, otherwise it resolvs to the production one. Therefore this function returns a relative url for Web.

Mobile apps don't support relative url."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I expanded to explain more on the relative url, and why we do this.


if (response.statusCode != HttpStatus.ok) {
print(response.body);
return CocoonResponse<List<CommitStatus>>()
..error =
'$_baseApiUrl/public/get-status returned ${response.statusCode}';
..error = '/api/public/get-status returned ${response.statusCode}';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this line doesn't call _apiEndpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just an error message, so I think just giving the endpoint is fine. I was trying to keep the error messages concise so they could be shown in the UI.

});
});
}

class MockHttpClient extends Mock implements Client {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good use case to put the new tests into a group: https://flutter.dev/docs/cookbook/testing/unit/introduction#5-combine-multiple-tests-in-a-group

And a group can avoid the redundant setup code. Is that right? @jonahwilliams

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the tests are grouped by the endpoint they relate to. Should we swap it so we group by the functionality under test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine.

@jonahwilliams
Copy link
Member

There might be a better approach, but that's what I came up with in 5 minutes. I would sync with the rest of the infra team.

@CaseyHillers
Copy link
Contributor Author

Filed difference in test bug here: flutter/flutter#44370

@CaseyHillers
Copy link
Contributor Author

@jonahwilliams is it okay to table running the tests on chrome on Cirrus? We can't add Google chrome via the cirrus yml, so that is going to be a bigger change that requires syncing with the infra team and more research.

I can comment the line out on cirrus.yml and link to a Github issue on it to enable web tests.

Copy link
Contributor

@digiter digiter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

});
});
}

class MockHttpClient extends Mock implements Client {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine.

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