[PSM Interop] Improve error messages in the affinity test (#33031)

Previously the error message didn't provide much context, example:

```py
Traceback (most recent call last):
  File "/tmpfs/tmp/tmp.BqlenMyXyk/grpc/tools/run_tests/xds_k8s_test_driver/tests/affinity_test.py", line 127, in test_affinity
    self.assertLen(
AssertionError: [] has length of 0, expected 1.
```

ref b/279990584.
pull/33043/head
Sergii Tkachenko 2 years ago committed by GitHub
parent 3fb738b9b1
commit 448084c186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      tools/run_tests/xds_k8s_test_driver/tests/affinity_test.py

@ -124,15 +124,28 @@ class AffinityTest(xds_k8s_testcase.RegularXdsKubernetesTestCase):
rpc_distribution = xds_url_map_testcase.RpcDistributionStats(
json_lb_stats)
self.assertEqual(1, rpc_distribution.num_peers)
# Check subchannel states.
# One should be READY.
ready_channels = test_client.find_subchannels_with_state(
_ChannelzChannelState.READY)
self.assertLen(
test_client.find_subchannels_with_state(
_ChannelzChannelState.READY),
ready_channels,
1,
msg=('(AffinityTest) The client expected to have one READY'
' subchannel to one of the test servers. Found'
f' {len(ready_channels)} instead.'),
)
# The rest should be IDLE.
expected_idle_channels = _REPLICA_COUNT - 1
idle_channels = test_client.find_subchannels_with_state(
_ChannelzChannelState.IDLE)
self.assertLen(
test_client.find_subchannels_with_state(
_ChannelzChannelState.IDLE),
2,
idle_channels,
expected_idle_channels,
msg=('(AffinityTest) The client expected to have IDLE'
f' subchannels to {expected_idle_channels} of the test'
f' servers. Found {len(idle_channels)} instead.'),
)
# Remember the backend inuse, and turn it down later.
first_backend_inuse = list(

Loading…
Cancel
Save