aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio_tests/tests/unit/framework/interfaces/base/_sequence.py
blob: 571d0e1e632e14db535c53f9b4128c49eb0e8860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Copyright 2015, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Part of the tests of the base interface of RPC Framework."""

import collections
import enum

from grpc.framework.interfaces.base import base
from tests.unit.framework.common import test_constants


class Invocation(
    collections.namedtuple(
        'Invocation', ('timeout', 'initial_metadata', 'payload', 'complete',))):
  """A recipe for operation invocation.

  Attributes:
    timeout: A duration in seconds to pass to the system under test as the
      operation's timeout value.
    initial_metadata: A boolean indicating whether or not to pass initial
      metadata when invoking the operation.
    payload: A boolean indicating whether or not to pass a payload when
      invoking the operation.
    complete: A boolean indicating whether or not to indicate completion of
      transmissions from the invoking side of the operation when invoking the
      operation.
  """


class Transmission(
    collections.namedtuple(
        'Transmission', ('initial_metadata', 'payload', 'complete',))):
  """A recipe for a single transmission in an operation.

  Attributes:
    initial_metadata: A boolean indicating whether or not to pass initial
      metadata as part of the transmission.
    payload: A boolean indicating whether or not to pass a payload as part of
      the transmission.
    complete: A boolean indicating whether or not to indicate completion of
      transmission from the transmitting side of the operation as part of the
      transmission.
  """


class Intertransmission(
    collections.namedtuple('Intertransmission', ('invocation', 'service',))):
  """A recipe for multiple transmissions in an operation.

  Attributes:
    invocation: An integer describing the number of payloads to send from the
      invocation side of the operation to the service side.
    service: An integer describing the number of payloads to send from the
      service side of the operation to the invocation side.
  """


class Element(collections.namedtuple('Element', ('kind', 'transmission',))):
  """A sum type for steps to perform when testing an operation.

  Attributes:
    kind: A Kind value describing the kind of step to perform in the test.
    transmission: Only valid for kinds Kind.INVOCATION_TRANSMISSION and
      Kind.SERVICE_TRANSMISSION, a Transmission value describing the details of
      the transmission to be made.
  """

  @enum.unique
  class Kind(enum.Enum):
    INVOCATION_TRANSMISSION = 'invocation transmission'
    SERVICE_TRANSMISSION = 'service transmission'
    INTERTRANSMISSION = 'intertransmission'
    INVOCATION_CANCEL = 'invocation cancel'
    SERVICE_CANCEL = 'service cancel'
    INVOCATION_FAILURE = 'invocation failure'
    SERVICE_FAILURE = 'service failure'


class OutcomeKinds(
    collections.namedtuple('Outcome', ('invocation', 'service',))):
  """A description of the expected outcome of an operation test.

  Attributes:
    invocation: The base.Outcome.Kind value expected on the invocation side of
      the operation.
    service: The base.Outcome.Kind value expected on the service side of the
      operation.
  """


class Sequence(
    collections.namedtuple(
        'Sequence',
        ('name', 'maximum_duration', 'invocation', 'elements',
         'outcome_kinds',))):
  """Describes at a high level steps to perform in a test.

  Attributes:
    name: The string name of the sequence.
    maximum_duration: A length of time in seconds to allow for the test before
      declaring it to have failed.
    invocation: An Invocation value describing how to invoke the operation
      under test.
    elements: A sequence of Element values describing at coarse granularity
      actions to take during the operation under test.
    outcome_kinds: An OutcomeKinds value describing the expected outcome kinds
      of the test.
  """

_EASY = Sequence(
    'Easy',
    test_constants.TIME_ALLOWANCE,
    Invocation(test_constants.LONG_TIMEOUT, True, True, True),
    (
        Element(
            Element.Kind.SERVICE_TRANSMISSION, Transmission(True, True, True)),
    ),
    OutcomeKinds(base.Outcome.Kind.COMPLETED, base.Outcome.Kind.COMPLETED))

_PEASY = Sequence(
    'Peasy',
    test_constants.TIME_ALLOWANCE,
    Invocation(test_constants.LONG_TIMEOUT, True, True, False),
    (
        Element(
            Element.Kind.SERVICE_TRANSMISSION, Transmission(True, True, False)),
        Element(
            Element.Kind.INVOCATION_TRANSMISSION,
            Transmission(False, True, True)),
        Element(
            Element.Kind.SERVICE_TRANSMISSION, Transmission(False, True, True)),
    ),
    OutcomeKinds(base.Outcome.Kind.COMPLETED, base.Outcome.Kind.COMPLETED))


# TODO(issue 2959): Finish this test suite. This tuple of sequences should
# contain at least the values in the Cartesian product of (half-duplex,
# full-duplex) * (zero payloads, one payload, test_constants.STREAM_LENGTH
# payloads) * (completion, cancellation, expiration, programming defect in
# servicer code).
SEQUENCES = (
    _EASY,
    _PEASY,
)