Example #1
0
def test_public_sdk_sample(native_sdk):
    nativeagent._force_initialize(native_sdk)  #pylint:disable=protected-access
    from . import onesdksamplepy
    onesdksamplepy.main()
    assert_resolve_all(native_sdk)

    def check_remote_node(node):
        assert node.vals[:3] == ('dummyPyMethod', 'DummyPyService',
                                 'dupypr://localhost/dummyEndpoint')
        assert node.protocol_name == 'DUMMY_PY_PROTOCOL'

    def check_root(root):
        assert type(root) is sdkmockiface.InRemoteCallHandle
        assert root.vals == ('main', 'main', 'main')

        def check_remote_child(child):
            link, node = child
            assert link == sdkmockiface.TracerHandle.LINK_CHILD
            assert type(node) is sdkmockiface.OutRemoteCallHandle
            check_remote_node(node)
            assert node.vals[3:] == (onesdk.ChannelType.IN_PROCESS,
                                     'localhost')

        def check_remote_child_err(child):
            check_remote_child(child)
            node = child[1]
            assert node.err_info == (RTERR_QNAME, 'remote error message')

        def check_remote_child_ok(child):
            check_remote_child(child)
            node = child[1]
            assert node.err_info is None

            def check_linked_remote_thread(rmchild):
                rmlink, rmnode = rmchild
                assert rmlink == sdkmockiface.TracerHandle.LINK_TAG
                assert type(rmnode) is sdkmockiface.InRemoteCallHandle
                check_remote_node(rmnode)
                assert rmnode.children

                def chk_dbcall(dbchild):
                    dblnk, dbnode = dbchild
                    assert dblnk == sdkmockiface.TracerHandle.LINK_CHILD
                    assert type(dbnode) is sdkmockiface.DbRequestHandle

                chk_all(rmnode.children, chk_dbcall)

            chk_seq(node.children, [check_linked_remote_thread])

        chk_seq(root.children,
                [check_remote_child_ok] * 2 + [check_remote_child_err])

    def check_is_linked(root):
        assert root.linked_parent

    def check_web_request(root):
        assert type(root) is sdkmockiface.InWebReqHandle

    chk_seq(native_sdk.finished_paths,
            [check_web_request] + [check_is_linked] * 2 + [check_root])
def test_public_sdk_sample(native_sdk):
    nativeagent._force_initialize(native_sdk)  #pylint:disable=protected-access
    from . import onesdksamplepy
    onesdksamplepy.main()
    assert_resolve_all(native_sdk)

    def check_is_linked(root):
        assert root.linked_parent

    def check_is_inprocess_link(root):
        assert type(root) is sdkmockiface.InProcessLinkTracerHandle

    def check_incoming_web_request(root):
        assert type(root) is sdkmockiface.InWebReqHandle
        assert len(root.custom_attribs) == 3
        key, value = root.custom_attribs[0]
        assert key == 'custom int attribute'
        assert value == 42
        key, value = root.custom_attribs[1]
        assert key == 'custom float attribute'
        assert value == 1.778
        key, value = root.custom_attribs[2]
        assert key == 'custom string attribute'
        assert value == 'snow is falling'

    def check_outgoing_web_request(root):
        assert type(root) is sdkmockiface.OutWebReqHandle
        assert root.resp_code == 200
        assert len(root.req_hdrs) == 1
        header, value = root.req_hdrs[0]
        assert header == 'X-not-a-useful-header'
        assert value == 'python-was-here'
        assert len(root.resp_hdrs) == 1
        header, value = root.resp_hdrs[0]
        assert header == 'Content-Length'
        assert value == '1234'

    def check_is_outgoing_messaging(root):
        assert type(root) is sdkmockiface.OutMsgTracerHandle
        assert root.vendor_message_id == 'msgId'
        assert root.correlation_id == 'corrId'

    def check_custom_service(root):
        assert type(root) is sdkmockiface.CustomServiceTracerHandle
        assert root.service_method == 'my_fancy_transaction'
        assert root.service_name == 'MyFancyService'

    chk_seq(native_sdk.finished_paths,
            ([check_incoming_web_request] + [check_outgoing_web_request] +
             [check_is_outgoing_messaging] + [check_custom_service] +
             [check_is_linked] * 3 + [check_root] + [check_is_linked] +
             [check_is_inprocess_link]))
Example #3
0
def set_sdk():
    nativeagent.initialize(SDKMockInterface())
    yield set_sdk
    nativeagent._force_initialize(None)  #pylint:disable=protected-access
def test_public_sdk_sample(native_sdk_noinit, monkeypatch):
    # pylint:disable=protected-access
    monkeypatch.setattr(
        nativeagent, "initialize",
        lambda libname: nativeagent._force_initialize(native_sdk_noinit))
    from . import onesdksamplepy
    onesdksamplepy.main()
    native_sdk = native_sdk_noinit

    pysdk_tech = sdkmockiface.ProcessTech(oneagent._PROCESS_TECH_ONEAGENT_SDK,
                                          'Python', oneagent.__version__)
    assert pysdk_tech in native_sdk.techs
    assert any(tt for tt in native_sdk.techs
               if tt.type == oneagent._PROCESS_TECH_PYTHON)

    assert_resolve_all(native_sdk)

    def check_is_linked(root):
        assert root.linked_parent

    def check_is_inprocess_link(root):
        assert type(root) is sdkmockiface.InProcessLinkTracerHandle

    def check_incoming_web_request(root):
        assert type(root) is sdkmockiface.InWebReqHandle
        assert len(root.custom_attribs) == 3
        key, value = root.custom_attribs[0]
        assert key == 'custom int attribute'
        assert value == 42
        key, value = root.custom_attribs[1]
        assert key == 'custom float attribute'
        assert value == 1.778
        key, value = root.custom_attribs[2]
        assert key == 'custom string attribute'
        assert value == 'snow is falling'

    def check_outgoing_web_request(root):
        assert type(root) is sdkmockiface.OutWebReqHandle
        assert root.resp_code == 200
        assert len(root.req_hdrs) == 1
        header, value = root.req_hdrs[0]
        assert header == 'X-not-a-useful-header'
        assert value == 'python-was-here'
        assert len(root.resp_hdrs) == 1
        header, value = root.resp_hdrs[0]
        assert header == 'Content-Length'
        assert value == '1234'

    def check_is_outgoing_messaging(root):
        assert type(root) is sdkmockiface.OutMsgTracerHandle
        assert root.vendor_message_id == 'msgId'
        assert root.correlation_id == 'corrId'

    def check_custom_service(root):
        assert type(root) is sdkmockiface.CustomServiceTracerHandle
        assert root.service_method == 'my_fancy_transaction'
        assert root.service_name == 'MyFancyService'

    chk_seq(native_sdk.finished_paths,
            ([check_incoming_web_request] + [check_outgoing_web_request] +
             [check_is_outgoing_messaging] + [check_custom_service] +
             [check_is_linked] * 3 + [check_root] + [check_is_linked] +
             [check_is_inprocess_link]))