|
114 | 114 | "metadata": {}, |
115 | 115 | "outputs": [], |
116 | 116 | "source": [ |
| 117 | + "import json\n", |
117 | 118 | "import time\n", |
118 | 119 | "import utils\n", |
119 | 120 | "from apimrequests import ApimRequests\n", |
| 121 | + "from apimtesting import ApimTesting\n", |
120 | 122 | "\n", |
121 | 123 | "def zzzs():\n", |
122 | 124 | " sleep_in_s = 5\n", |
123 | 125 | " utils.print_message(f'Waiting for {sleep_in_s} seconds for the backend timeouts to reset before starting the next set of calls', blank_above = True)\n", |
124 | 126 | " time.sleep(sleep_in_s) # Wait a bit before the next set of calls to allow for the backend timeouts to reset\n", |
125 | 127 | "\n", |
| 128 | + "tests = ApimTesting(\"Load Balancing Sample Tests\")\n", |
| 129 | + "\n", |
126 | 130 | "# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door. If so, assume that APIM is not directly accessible and use the Front Door URL instead.\n", |
127 | 131 | "endpoint_url = utils.test_url_preflight_check(deployment, rg_name, apim_gateway_url)\n", |
128 | 132 | "reqs = ApimRequests(endpoint_url)\n", |
129 | 133 | "\n", |
| 134 | + "# Quick test to verify load balancing API is accessible\n", |
| 135 | + "output = reqs.singleGet('/lb-prioritized', msg = 'Quick test of load balancing API')\n", |
| 136 | + "# We expect to see a priority 1 backend (at index 0) with a count of 1 as this is the first request.\n", |
| 137 | + "tests.verify(json.loads(output)['index'], 0)\n", |
| 138 | + "tests.verify(json.loads(output)['count'], 1)\n", |
| 139 | + "\n", |
| 140 | + "# The following test assertions are rather basic. The real verification comes in the charts in the subsequent cell.\n", |
| 141 | + "\n", |
130 | 142 | "# 1) Prioritized API calls\n", |
131 | | - "utils.print_message('1/4: Starting API calls for prioritized distribution (50/50)')\n", |
132 | | - "api_results_prioritized = reqs.multiGet('/lb-prioritized', runs = 15, msg = 'Calling prioritized APIs')\n", |
133 | | - "zzzs()\n", |
| 143 | + "utils.print_message('1/5: Starting API calls for prioritized distribution (50/50)')\n", |
| 144 | + "output = reqs.multiGet('/lb-prioritized', runs = 15, msg = 'Calling prioritized APIs')\n", |
| 145 | + "tests.verify(len(output), 15)\n", |
134 | 146 | "\n", |
135 | | - "# 2) Weighted API calls\n", |
136 | | - "utils.print_message('2/4: Starting API calls for weighted distribution (50/50)', blank_above = True)\n", |
137 | | - "api_results_weighted_equal = reqs.multiGet('/lb-weighted-equal', runs = 15, msg = 'Calling weighted (equal) APIs')\n", |
| 147 | + "# # 2) Weighted API calls\n", |
138 | 148 | "zzzs()\n", |
| 149 | + "utils.print_message('2/5: Starting API calls for weighted distribution (50/50)', blank_above = True)\n", |
| 150 | + "output = reqs.multiGet('/lb-weighted-equal', runs = 15, msg = 'Calling weighted (equal) APIs')\n", |
| 151 | + "tests.verify(len(output), 15)\n", |
139 | 152 | "\n", |
140 | | - "# 3) Weighted API calls\n", |
141 | | - "utils.print_message('3/4: Starting API calls for weighted distribution (80/20)', blank_above = True)\n", |
142 | | - "api_results_weighted_unequal = reqs.multiGet('/lb-weighted-unequal', runs = 15, msg = 'Calling weighted (unequal) APIs')\n", |
| 153 | + "# # 3) Weighted API calls\n", |
143 | 154 | "zzzs()\n", |
| 155 | + "utils.print_message('3/5: Starting API calls for weighted distribution (80/20)', blank_above = True)\n", |
| 156 | + "output = reqs.multiGet('/lb-weighted-unequal', runs = 15, msg = 'Calling weighted (unequal) APIs')\n", |
| 157 | + "tests.verify(len(output), 15)\n", |
144 | 158 | "\n", |
145 | 159 | "# 4) Prioritized & weighted API calls\n", |
146 | | - "utils.print_message('4/4: Starting API calls for prioritized & weighted distribution', blank_above = True)\n", |
147 | | - "api_results_prioritized_and_weighted = reqs.multiGet('/lb-prioritized-weighted', runs = 20, msg = 'Calling prioritized & weighted APIs')\n", |
148 | 160 | "zzzs()\n", |
| 161 | + "utils.print_message('4/5: Starting API calls for prioritized & weighted distribution', blank_above = True)\n", |
| 162 | + "output = reqs.multiGet('/lb-prioritized-weighted', runs = 20, msg = 'Calling prioritized & weighted APIs')\n", |
| 163 | + "tests.verify(len(output), 20)\n", |
149 | 164 | "\n", |
150 | 165 | "# 5) Prioritized & weighted API calls (500ms sleep)\n", |
151 | | - "utils.print_message('5/4: Starting API calls for prioritized & weighted distribution (500ms sleep)', blank_above = True)\n", |
152 | | - "api_results_prioritized_and_weighted_sleep = reqs.multiGet('/lb-prioritized-weighted', runs = 20, msg = 'Calling prioritized & weighted APIs', sleepMs = 500)\n", |
| 166 | + "zzzs()\n", |
| 167 | + "utils.print_message('5/5: Starting API calls for prioritized & weighted distribution (500ms sleep)', blank_above = True)\n", |
| 168 | + "output = reqs.multiGet('/lb-prioritized-weighted', runs = 20, msg = 'Calling prioritized & weighted APIs', sleepMs = 500)\n", |
| 169 | + "tests.verify(len(output), 20)\n", |
| 170 | + "\n", |
| 171 | + "tests.print_summary()\n", |
153 | 172 | "\n", |
154 | 173 | "utils.print_ok('All done!')" |
155 | 174 | ] |
|
0 commit comments