Skip to content

Commit

Permalink
Adding --format to the client and adding --format AuTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bneradt authored and bneradt committed Jun 8, 2020
1 parent 338a04c commit 6970ab5
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 0 deletions.
6 changes: 6 additions & 0 deletions local/src/client/verifier-client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ Engine::command_run()
return;
}

auto key_format_arg{arguments.get("format")};
if (key_format_arg) {
HttpHeader::_key_format = key_format_arg[0];
}

auto keys_arg{arguments.get("keys")};
if (!keys_arg.empty()) {
for (auto const &key : keys_arg) {
Expand Down Expand Up @@ -603,6 +608,7 @@ main(int /* argc */, char const *argv[])
1,
"")
.add_option("--rate", "", "Specify desired transacton rate", "", 1, "")
.add_option("--format", "-f", "Transaction key format", "", 1, "")
.add_option(
"--strict",
"-s",
Expand Down
122 changes: 122 additions & 0 deletions test/autests/gold_tests/format_argument/format_argument.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'''
Verify --format argument parsing.
'''
# @file
#
# Copyright 2020, Verizon Media
# SPDX-License-Identifier: Apache-2.0
#


Test.Summary = '''
Verify --format argument parsing.
'''

#
# Test 1: Test with the URL as a key. This is not unique across transactions,
# so only one transaction will be registered.
#
r = Test.AddTestRun('--format "{field.url}"')
client = r.AddClientProcess("client1", "replay_files/unique_by_host", http_ports=[8080],
other_args="--verbose diag --format '{url}'")
server = r.AddServerProcess("server1", "replay_files/unique_by_host", http_ports=[8081],
other_args="--verbose diag --format '{url}'")
proxy = r.AddProxyProcess("proxy1", listen_port=8080, server_port=8081)

# The client will see each transaction as unique and will send them as such.
client.Streams.stdout += Testers.ContainsExpression(
"Parsed 3 transactions",
"Three transactions should be parsed by the client.")

client.Streams.stdout += Testers.ContainsExpression(
'Equals Violation: Different.*Actual Value: "first"',
"The server will always reply with the first response.")

client.Streams.stdout += Testers.ContainsExpression(
'Key: "/same/path"',
"The key should be parsed from the URL, not the uuid.")

# The server, however, uses the key which, since we're using the URL which is
# the same across transactions, will only register the first transaction.
server.Streams.stdout += Testers.ContainsExpression(
'Correct Value: "first", Actual Value: "second"',
"The second transaction should come up as a violation.")

server.Streams.stdout += Testers.ContainsExpression(
'Correct Value: "first", Actual Value: "third"',
"The third transaction should come up as a violation.")

server.Streams.stdout += Testers.ContainsExpression(
"Ready with 1 transactions",
"Only one transaction should be parsed by the server.")

server.Streams.stdout += Testers.ContainsExpression(
'Key: "/same/path"',
"The key should be parsed from the URL, not the uuid.")
#
# Test 2: Verify using the host as a key, which is unique across transactions.
#
r = Test.AddTestRun('--format "{field.host}"')
client = r.AddClientProcess("client2", "replay_files/unique_by_host", http_ports=[8080],
other_args="--verbose diag --format '{field.host}'")
server = r.AddServerProcess("server2", "replay_files/unique_by_host", http_ports=[8081],
other_args="--verbose diag --format '{field.host}'")
proxy = r.AddProxyProcess("proxy2", listen_port=8080, server_port=8081)

client.Streams.stdout += Testers.ContainsExpression(
"Parsed 3 transactions",
"Three transactions should be parsed by the client.")

client.Streams.stdout += Testers.ExcludesExpression(
"Violation:",
"There should be no verification errors because there are none added.")

client.Streams.stdout += Testers.ContainsExpression(
'Key: "host.one"',
"The key should be parsed from the host, not the uuid.")

server.Streams.stdout += Testers.ExcludesExpression(
"Violation:",
"There should be no verification errors because there are none added.")

server.Streams.stdout += Testers.ContainsExpression(
"Ready with 3 transactions",
"Three transactions should be parsed by the server.")

server.Streams.stdout += Testers.ContainsExpression(
'Key: "host.one"',
"The key should be parsed from the host, not the uuid.")

#
# Test 3: Use a more complicated key made up of two specifiers.
#
r = Test.AddTestRun('--format "{field.host}/{url}"')
client = r.AddClientProcess("client3", "replay_files/unique_by_host", http_ports=[8080],
other_args="--verbose diag --format '{field.host}/{url}'")
server = r.AddServerProcess("server3", "replay_files/unique_by_host", http_ports=[8081],
other_args="--verbose diag --format '{field.host}/{url}'")
proxy = r.AddProxyProcess("proxy3", listen_port=8080, server_port=8081)

client.Streams.stdout += Testers.ContainsExpression(
"Parsed 3 transactions",
"Three transactions should be parsed by the client.")

client.Streams.stdout += Testers.ExcludesExpression(
"Violation:",
"There should be no verification errors because there are none added.")

client.Streams.stdout += Testers.ContainsExpression(
'Key: "host.one//same/path"',
"The key should be parsed from the host/url, not the uuid.")

server.Streams.stdout += Testers.ExcludesExpression(
"Violation:",
"There should be no verification errors because there are none added.")

server.Streams.stdout += Testers.ContainsExpression(
"Ready with 3 transactions",
"Three transactions should be parsed by the server.")

server.Streams.stdout += Testers.ContainsExpression(
'Key: "host.one//same/path"',
"The key should be parsed from the host/url, not the uuid.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# *** NOTE ***
# Unlike the majority of the other replay files in this repo, the uuid values
# across the transactions is the same for each transaction. The validations
# assume '--format {field.host}' since the uuid is the same across all
# transactions. This is intentional to test the use of other values as the key.

meta:
version: "1.0"

sessions:
- protocol: [ ipv4, tcp ]
transactions:
- all:
headers:
fields:
- [ uuid, 1 ]

client-request:
version: "1.1"
scheme: "http"
method: "GET"
url: "/same/path"
headers:
fields:
- [ Host, host.one ]
- [ X-Request, first ]
proxy-request:
version: "1.1"
scheme: "http"
method: "GET"
url: "/same/path"
headers:
fields:
- [ Host, host.one ]
- [ X-Request, first, equal ]
server-response:
status: 200
reason: OK
content:
size: 0
headers:
fields:
- [ Content-Type, text/html ]
- [ Content-Length, 0 ]
- [ X-Response, first ]
proxy-response:
status: 200
reason: OK
content:
size: 0
headers:
fields:
- [ Content-Type, text/html ]
- [ Content-Length, 0 ]
- [ X-Response, first, equal ]

- all:
headers:
fields:
- [ uuid, 1 ]

client-request:
version: "1.1"
scheme: "http"
method: "GET"
url: "/same/path"
headers:
fields:
- [ Host, host.two ]
- [ X-Request, second ]
proxy-request:
version: "1.1"
scheme: "http"
method: "GET"
url: "/same/path"
headers:
fields:
- [ Host, host.two ]
- [ X-Request, second, equal ]
server-response:
status: 200
reason: OK
content:
size: 0
headers:
fields:
- [ Content-Type, text/html ]
- [ Content-Length, 0 ]
- [ X-Response, two ]
proxy-response:
status: 200
reason: OK
content:
size: 0
headers:
fields:
- [ Content-Type, text/html ]
- [ Content-Length, 0 ]
- [ X-Response, two, equal ]

- all:
headers:
fields:
- [ uuid, 1 ]

client-request:
version: "1.1"
scheme: "http"
method: "GET"
url: "/same/path"
headers:
fields:
- [ Host, host.three ]
- [ X-Request, third ]
proxy-request:
version: "1.1"
scheme: "http"
method: "GET"
url: "/same/path"
headers:
fields:
- [ Host, host.three ]
- [ X-Request, third, equal ]
server-response:
status: 200
reason: OK
content:
size: 0
headers:
fields:
- [ Content-Type, text/html ]
- [ Content-Length, 0 ]
- [ X-Response, three ]
proxy-response:
status: 200
reason: OK
content:
size: 0
headers:
fields:
- [ Content-Type, text/html ]
- [ Content-Length, 0 ]
- [ X-Response, three, equal ]

0 comments on commit 6970ab5

Please sign in to comment.