コード例 #1
0
ファイル: stream_test.py プロジェクト: Kashomon/test-infra
    def test_main(self):
        # It's easier to run a full integration test with stubbed-out
        # external interfaces and validate the trace than it is to test
        # each individual piece.
        # The components are mostly tested in make_*_test.py.

        db = model.Database(':memory:')
        fakesub = FakeSub([
            [
                ('a', Attrs({'eventType': 'OBJECT_DELETE'})),
            ],
            [
                ('b', Attrs({
                    'eventType': 'OBJECT_FINALIZE',
                    'objectId': 'logs/fake/123/finished.json',
                    'bucketId': 'kubernetes-jenkins'})),
            ],
            [],
            [
                ('c', Attrs({
                    'eventType': 'OBJECT_FINALIZE',
                    'objectId': 'logs/fake/123/finished.json',
                    'bucketId': 'kubernetes-jenkins'})),
            ],
            [],
            [
                ('d', Attrs({
                    'eventType': 'OBJECT_FINALIZE',
                    'objectId': 'logs/fake/124/started.json'})),
            ],
            [],
        ])
        faketable = FakeTable('day', stream.load_schema(FakeSchemaField), fakesub.trace)
        tables = {'day': (faketable, 'incr')}
        stream.main(
            db, fakesub, tables, make_db_test.MockedClient, [1, 0, 0, 0].pop)

        # uncomment if the trace changes
        # import pprint; pprint.pprint(fakesub.trace)
        # self.maxDiff = 3000

        now = make_db_test.MockedClient.NOW

        self.assertEqual(
            fakesub.trace,
            [['pull', False], ['pull', True], ['pull', True],
             ['ack', ['a']],
             ['modify-ack', ['b'], 180],
             ['ack', ['b']],
             ['insert-data',
              ([[5,
                 now - 5,
                 now,
                 True,
                 u'SUCCESS',
                 None,
                 u'gs://kubernetes-jenkins/logs/fake/123',
                 u'fake',
                 123,
                 [],
                 [{'name': 'Foo', 'time': 3.0},
                  {'failed': True,
                   'failure_text': 'stacktrace',
                   'name': 'Bad',
                   'time': 4.0}],
                 2,
                 1,
                 None]],
               [1]),
              {'skip_invalid_rows': True}],
             ['pull', False], ['pull', True],
             ['modify-ack', ['c'], 180],
             ['ack', ['c']],
             ['pull', False], ['pull', True],
             ['ack', ['d']]])
コード例 #2
0
ファイル: stream_test.py プロジェクト: yrj2011/jx-test-infra
    def test_main(self):
        # It's easier to run a full integration test with stubbed-out
        # external interfaces and validate the trace than it is to test
        # each individual piece.
        # The components are mostly tested in make_*_test.py.

        db = model.Database(':memory:')
        fakesub = FakeSub([
            [
                ('a', Attrs({'eventType': 'OBJECT_DELETE'})),
            ],
            [
                ('b',
                 Attrs({
                     'eventType': 'OBJECT_FINALIZE',
                     'objectId': 'logs/fake/123/finished.json',
                     'bucketId': 'kubernetes-jenkins'
                 })),
            ],
            [],
            [
                ('c',
                 Attrs({
                     'eventType': 'OBJECT_FINALIZE',
                     'objectId': 'logs/fake/123/finished.json',
                     'bucketId': 'kubernetes-jenkins'
                 })),
            ],
            [],
            [
                ('d',
                 Attrs({
                     'eventType': 'OBJECT_FINALIZE',
                     'objectId': 'logs/fake/124/started.json'
                 })),
            ],
            [],
        ])
        faketable = FakeTable('day', stream.load_schema(FakeSchemaField),
                              fakesub.trace)
        tables = {'day': (faketable, 'incr')}
        stream.main(db, fakesub, tables, make_db_test.MockedClient,
                    [1, 0, 0, 0].pop)

        # uncomment if the trace changes
        # import pprint; pprint.pprint(fakesub.trace)
        # self.maxDiff = 3000

        now = make_db_test.MockedClient.NOW

        self.assertEqual(
            fakesub.trace,
            [['pull', False], ['pull', True], ['pull', True], ['ack', ['a']],
             ['modify-ack', ['b'], 180], ['ack', ['b']],
             [
                 'insert-data',
                 ([[
                     5, now - 5, now, True, u'SUCCESS', None,
                     u'gs://kubernetes-jenkins/logs/fake/123', u'fake', 123,
                     [],
                     [{
                         'name': 'Foo',
                         'time': 3.0
                     }, {
                         'failed': True,
                         'failure_text': 'stacktrace',
                         'name': 'Bad',
                         'time': 4.0
                     }], 2, 1, None
                 ]], [1]), {
                     'skip_invalid_rows': True
                 }
             ], ['pull', False], ['pull', True], ['modify-ack', ['c'], 180],
             ['ack', ['c']], ['pull', False], ['pull', True], ['ack', ['d']]])
コード例 #3
0
ファイル: stream_test.py プロジェクト: vijtrip2/test-infra-1
    def test_main(self):
        # It's easier to run a full integration test with stubbed-out
        # external interfaces and validate the trace than it is to test
        # each individual piece.
        # The components are mostly tested in make_*_test.py.

        db = model.Database(':memory:')
        fake_sub = FakeSub([
            FakePullResponse([
                FakeReceivedMessage(
                    'b',
                    FakePubSubMessage(
                        'no_data', {
                            'eventType': 'OBJECT_FINALIZE',
                            'objectId': 'logs/fake/123/finished.json',
                            'bucketId': 'kubernetes-jenkins'
                        }))
            ]),
            FakePullResponse([]),
            FakePullResponse([
                FakeReceivedMessage(
                    'c',
                    FakePubSubMessage(
                        'no_data', {
                            'eventType': 'OBJECT_FINALIZE',
                            'objectId': 'logs/fake/123/finished.json',
                            'bucketId': 'kubernetes-jenkins'
                        }))
            ]),
            FakePullResponse([]),
            FakePullResponse([
                FakeReceivedMessage(
                    'd',
                    FakePubSubMessage(
                        'no_data', {
                            'eventType': 'OBJECT_FINALIZE',
                            'objectId': 'logs/fake/124/started.json',
                            'bucketId': 'kubernetes-jenkins'
                        }))
            ]),
            FakePullResponse([]),
        ])
        fake_client = FakeClient()
        fake_table = FakeTable('day', stream.load_schema(FakeSchemaField))
        fake_sub_path = 'projects/{project_id}/subscriptions/{sub}'
        tables = {'day': (fake_table, 'incr')}
        stream.main(db, fake_sub, fake_sub_path, fake_client, tables,
                    self.fake_buckets, make_db_test.MockedClient, [1, 0, 0,
                                                                   0].pop)

        # uncomment if the trace changes
        # import pprint; pprint.pprint(fake_sub.trace)
        # import pprint; pprint.pprint(fake_client.trace)
        # self.maxDiff = 3000

        now = make_db_test.MockedClient.NOW

        self.assertEqual(
            fake_sub.trace,
            [['pull', fake_sub_path, False], ['pull', fake_sub_path, True],
             ['modify-ack', fake_sub_path, ['b'], 180],
             ['ack', fake_sub_path, ['b']], ['pull', fake_sub_path, False],
             ['pull', fake_sub_path, True],
             ['modify-ack', fake_sub_path, ['c'], 180],
             ['ack', fake_sub_path, ['c']], ['pull', fake_sub_path, False],
             ['pull', fake_sub_path, True], ['ack', fake_sub_path, ['d']]])

        self.assertEqual(fake_client.trace, [[
            'insert-rows',
            ([{
                'elapsed':
                5,
                'finished':
                now,
                'job':
                'fake',
                'number':
                123,
                'passed':
                True,
                'path':
                'gs://kubernetes-jenkins/logs/fake/123',
                'result':
                'SUCCESS',
                'started':
                now - 5,
                'test': [{
                    'name': 'Foo',
                    'time': 3.0
                }, {
                    'failed': True,
                    'failure_text': 'stacktrace',
                    'name': 'Bad',
                    'time': 4.0
                }],
                'tests_failed':
                1,
                'tests_run':
                2
            }], ), {
                'skip_invalid_rows': True
            }
        ]])