You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by al...@apache.org on 2020/08/22 11:33:00 UTC
[skywalking-python] 01/03: update test
This is an automated email from the ASF dual-hosted git repository.
alonelaval pushed a commit to branch process-propagation
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 78bc533129476a27c2d61e5dd269b37f7b154a50
Author: huawei <hu...@bit-s.cn>
AuthorDate: Sat Aug 22 19:05:41 2020 +0800
update test
---
README.md | 9 ++++++-
tests/plugin/docker/Dockerfile.tool | 2 +-
tests/plugin/sw_process/expected.data.yml | 40 ++++++++++++++--------------
tests/plugin/sw_process/services/consumer.py | 6 +----
tests/plugin/sw_process/services/provider.py | 3 +--
tests/plugin/sw_process/test_process.py | 5 +---
6 files changed, 32 insertions(+), 33 deletions(-)
diff --git a/README.md b/README.md
index 649b3c4..1900fb1 100755
--- a/README.md
+++ b/README.md
@@ -88,6 +88,7 @@ from time import sleep
from skywalking import Component
from skywalking.decorators import trace, runnable
from skywalking.trace.context import SpanContext, get_context
+from skywalking.trace.ipc.process import SwProcess
@trace() # the operation name is the method name('some_other_method') by default
def some_other_method():
@@ -103,10 +104,16 @@ def some_method():
def some_method():
some_other_method()
-from threading import Thread
+from threading import Thread
t = Thread(target=some_method)
t.start()
+# When another process is started, agents will also be started in other processes,
+# supporting only the process mode of spawn.
+p1 = SwProcess(target=some_method)
+p1.start()
+p1.join()
+
context: SpanContext = get_context()
with context.new_entry_span(op=str('https://github.com/apache/skywalking')) as span:
diff --git a/tests/plugin/docker/Dockerfile.tool b/tests/plugin/docker/Dockerfile.tool
index f4283f4..e88d0ca 100644
--- a/tests/plugin/docker/Dockerfile.tool
+++ b/tests/plugin/docker/Dockerfile.tool
@@ -19,7 +19,7 @@ FROM openjdk:8
WORKDIR /tests
-ARG COMMIT_HASH=3c9d7099f05dc4a4b937c8a47506e56c130b6221
+ARG COMMIT_HASH=8a48c49b4420df5c9576d2aea178b2ebcb7ecd09
ADD https://github.com/apache/skywalking-agent-test-tool/archive/${COMMIT_HASH}.tar.gz .
diff --git a/tests/plugin/sw_process/expected.data.yml b/tests/plugin/sw_process/expected.data.yml
index 7eebf83..c295a84 100644
--- a/tests/plugin/sw_process/expected.data.yml
+++ b/tests/plugin/sw_process/expected.data.yml
@@ -37,7 +37,7 @@ segmentItems:
- parentEndpoint: /users
networkAddress: 'provider:9091'
refType: CrossProcess
- parentSpanId: 1
+ parentSpanId: 0
parentTraceSegmentId: not null
parentServiceInstance: not null
parentService: consumer
@@ -87,12 +87,12 @@ segmentItems:
parentSpanId: -1
spanId: 0
spanLayer: Http
- startTime: gt 0
- endTime: gt 0
+ startTime: gt 0
+ endTime: gt 0
componentId: 7002
isError: false
spanType: Exit
- peer: provider:9091
+ peer: not null
skipAnalysis: false
tags:
- key: http.method
@@ -108,36 +108,36 @@ segmentItems:
parentSpanId: 0
spanId: 1
spanLayer: Http
- tags:
- - key: http.method
- value: POST
- - key: url
- value: http://provider:9091/users
- - key: status.code
- value: '200'
startTime: gt 0
endTime: gt 0
componentId: 7002
+ isError: false
spanType: Exit
peer: provider:9091
skipAnalysis: false
- - operationName: /users
- operationId: 0
- parentSpanId: -1
- spanId: 0
- spanLayer: Http
tags:
- key: http.method
- value: GET
+ value: POST
- key: url
- value: http://0.0.0.0:9090/users
- - key: http.params
- value: "test=[test1,test2]\ntest2=[test2]"
+ value: 'http://provider:9091/users'
- key: status.code
value: '200'
+ - operationName: /users
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Http
startTime: gt 0
endTime: gt 0
componentId: 7001
+ isError: false
spanType: Entry
peer: not null
skipAnalysis: false
+ tags:
+ - key: http.method
+ value: GET
+ - key: url
+ value: 'http://0.0.0.0:9090/users'
+ - key: status.code
+ value: '200'
\ No newline at end of file
diff --git a/tests/plugin/sw_process/services/consumer.py b/tests/plugin/sw_process/services/consumer.py
index b2dcb3d..1eb6ac6 100644
--- a/tests/plugin/sw_process/services/consumer.py
+++ b/tests/plugin/sw_process/services/consumer.py
@@ -14,10 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-import time
+import time
import requests
-
from skywalking import agent, config
from skywalking.trace.ipc.process import SwProcess
import multiprocessing
@@ -41,9 +40,6 @@ if __name__ == '__main__':
@app.route("/users", methods=["POST", "GET"])
def application():
- from skywalking.trace.context import get_context
- get_context().put_correlation("correlation", "correlation")
-
p1 = SwProcess(target=post)
p1.start()
p1.join()
diff --git a/tests/plugin/sw_process/services/provider.py b/tests/plugin/sw_process/services/provider.py
index 6c2a04d..d043141 100644
--- a/tests/plugin/sw_process/services/provider.py
+++ b/tests/plugin/sw_process/services/provider.py
@@ -30,9 +30,8 @@ if __name__ == '__main__':
@app.route("/users", methods=["POST", "GET"])
def application():
- from skywalking.trace.context import get_context
time.sleep(0.5)
- return jsonify({"correlation": get_context().get_correlation("correlation")})
+ return jsonify({"song": "Despacito", "artist": "Luis Fonsi"})
PORT = 9091
app.run(host='0.0.0.0', port=PORT, debug=False)
diff --git a/tests/plugin/sw_process/test_process.py b/tests/plugin/sw_process/test_process.py
index 4efe2e5..ea88508 100644
--- a/tests/plugin/sw_process/test_process.py
+++ b/tests/plugin/sw_process/test_process.py
@@ -30,15 +30,12 @@ class TestPlugin(BasePluginTest):
def setUpClass(cls):
cls.compose = DockerCompose(filepath=dirname(inspect.getfile(cls)))
cls.compose.start()
- cls.compose.wait_for(cls.url(('consumer', '9090'), 'users?test=test1&test=test2&test2=test2'))
+ cls.compose.wait_for(cls.url(('consumer', '9090'), 'users'))
def test_plugin(self):
time.sleep(10)
self.validate()
- response = requests.get(TestPlugin.url(('consumer', '9090'), 'users'))
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response.json()["correlation"], "correlation")
if __name__ == '__main__':