-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[core] add testserver #19153
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
Merged
Merged
[core] add testserver #19153
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
6dff5d5
tests passing locally
iscai-msft 58c184a
move pytests.init to root
iscai-msft c7663fe
remove set formatting from windows run
iscai-msft bec31ed
try to fix windows testserver start
iscai-msft 405d5e8
uncomment testserver termination
iscai-msft fb692df
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
iscai-msft f826377
add devops scripts to start testserver
iscai-msft 6ceb795
scriptSource -> scriptPath
iscai-msft 0f10e5e
set env vars
iscai-msft c35fdc2
add pwsh testserver
iscai-msft f8fd247
return result
iscai-msft c4fd6d2
try retuning exit code
iscai-msft b322e28
remove ci work, make pytest fixture module level
iscai-msft 449f42a
tests working without pytest.ini
iscai-msft a021de2
only have testserver fixture in conftest
iscai-msft 7a68dd3
switch to package scope
iscai-msft df42f15
unite testserver setting
iscai-msft da62f4b
switch to environment variables
iscai-msft e06ebb4
see what happens if we don't kill testserver
iscai-msft 04ddbd0
cycle through ports
iscai-msft e860e8a
remove scripts
iscai-msft 2f39ad2
allow 2.7 compatibility
iscai-msft f503b2c
wait longer for pypy
iscai-msft 8ccce34
increase sleep to 2 for pypy
iscai-msft 30c6e39
move core testserver into tests
iscai-msft 20e593a
switch to urllib requesting to see if port open
iscai-msft 1483f8c
ignore coretestserver readme
iscai-msft 4cbf6a8
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
iscai-msft 0f2ae93
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
iscai-msft 3d12735
add readme rst
iscai-msft c4ac95b
ignore readme.rst
iscai-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import os | ||
| import signal | ||
| import argparse | ||
|
|
||
| def end_testserver(pid): | ||
|
|
||
| if os.name == 'nt': | ||
| os.kill(pid, signal.CTRL_C_EVENT) | ||
| else: | ||
| os.killpg(os.getpgid(pid), signal.SIGTERM) # Send the signal to all the process groups | ||
|
|
||
| if __name__ == '__main__': | ||
| parser = argparse.ArgumentParser( | ||
| description="Stop the testserver" | ||
| ) | ||
| parser.add_argument( | ||
| "-p", | ||
| "--pid", | ||
| dest="pid", | ||
| help="The pid of the subprocess the testserver is running on", | ||
| required=True, | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
| end_testserver(int(args.pid)) |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import os | ||
| import subprocess | ||
|
|
||
| def start_testserver(): | ||
| if os.name == 'nt': #On windows, subprocess creation works without being in the shell | ||
| os.environ["FLASK_APP"] = "coretestserver" | ||
| result = subprocess.Popen("flask run", env=dict(os.environ)) | ||
| else: | ||
| result = subprocess.Popen("FLASK_APP=coretestserver flask run", shell=True, preexec_fn=os.setsid) #On linux, have to set shell=True | ||
| print('##vso[task.setvariable variable=FLASK_PID]{}'.format(result.pid)) | ||
| print("This is used in the pipelines to set the FLASK_PID env var. If you want to stop this testserver, kill this PID.") | ||
|
|
||
| if __name__ == "__main__": | ||
| start_testserver() |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [pytest] | ||
| usefixtures=testserver | ||
| xfail_strict=true |
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
sdk/core/azure-core/tests/async_tests/test_testserver_async.py
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # -------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # | ||
| # The MIT License (MIT) | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the ""Software""), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| # THE SOFTWARE. | ||
| # | ||
| # -------------------------------------------------------------------------- | ||
| import pytest | ||
| from azure.core.pipeline.transport import HttpRequest, AioHttpTransport | ||
| """This file does a simple call to the testserver to make sure we can use the testserver""" | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_smoke(): | ||
| request = HttpRequest(method="GET", url="http://localhost:5000/basic/string") | ||
| async with AioHttpTransport() as sender: | ||
| response = await sender.send(request) | ||
| response.raise_for_status() | ||
| await response.load_body() | ||
| assert response.text() == "Hello, world!" |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # -------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # | ||
| # The MIT License (MIT) | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the ""Software""), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| # THE SOFTWARE. | ||
| # | ||
| # -------------------------------------------------------------------------- | ||
| from azure.core.pipeline.transport import HttpRequest, RequestsTransport | ||
| """This file does a simple call to the testserver to make sure we can use the testserver""" | ||
|
|
||
| def test_smoke(): | ||
| request = HttpRequest(method="GET", url="http://localhost:5000/basic/string") | ||
| with RequestsTransport() as sender: | ||
| response = sender.send(request) | ||
| response.raise_for_status() | ||
| assert response.text() == "Hello, world!" |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.