You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An itest_service is a binary that is intended to run for the duration of the integration test. Examples include databases, HTTP/RPC servers, queue consumers, external service mocks, etc.
@@ -61,6 +62,7 @@ All [common binary attributes](https://bazel.build/reference/be/common-definitio
| <a id="itest_service-autoassign_port"></a>autoassign_port | If true, the service manager will pick a free port and assign it to the service. The port will be interpolated into `$${PORT}` in the service's `http_health_check_address` and `args`. It will also be exported under the target's fully qualified label in the service-port mapping.<br><br>The assigned ports for all services are available for substitution in `http_health_check_address` and `args` (in case one service needs the address for another one.) For example, the following substitution: `args = ["-client-addr", "127.0.0.1:$${@@//label/for:service}"]`<br><br>The service-port mapping is a JSON string -> int map propagated through the `ASSIGNED_PORTS` env var. For example, a port can be retrieved with the following JS code: `JSON.parse(process.env["ASSIGNED_PORTS"])["@@//label/for:service"]`.<br><br>Alternately, the env will also contain the location of a binary that can return the port, for contexts without a readily-accessible JSON parser. For example, the following Bash command: `PORT=$($GET_ASSIGNED_PORT_BIN @@//label/for:service)` | Boolean | optional | `False` |
63
64
| <aid="itest_service-env"></a>env | The service manager will merge these variables into the environment when spawning the underlying binary. | <ahref="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional |`{}`|
65
+
| <aid="itest_service-error_on_forceful_shutdown"></a>error_on_forceful_shutdown | If set to True, the service manager will fail the service_test if the service had to be forcefully killed if the signal was not SIGKILL and after the shutdown timeout elapsed.<br><br>This needs to be False to have coverage of your services but don't want a them to be graceful at shutdown | Boolean | optional |`True`|
64
66
| <aid="itest_service-exe"></a>exe | The binary target to run. | <ahref="https://bazel.build/concepts/labels">Label</a> | required ||
65
67
| <aid="itest_service-expected_start_duration"></a>expected_start_duration | How long the service expected to take before passing a healthcheck. Any failing health checks before this duration elapses will not be logged. | String | optional |`"0s"`|
66
68
| <aid="itest_service-health_check"></a>health_check | If set, the service manager will execute this binary to check if the service came up in a healthy state. This check will be retried until it exits with a 0 exit code. When used in conjunction with autoassigned ports, use one of the methods described in `autoassign_port` to locate the service. | <ahref="https://bazel.build/concepts/labels">Label</a> | optional |`None`|
@@ -70,6 +72,8 @@ All [common binary attributes](https://bazel.build/reference/be/common-definitio
70
72
| <aid="itest_service-hot_reloadable"></a>hot_reloadable | If set to True, the service manager will propagate ibazel's reload notification over stdin instead of restarting the service. See the ruleset docstring for more info on using ibazel | Boolean | optional |`False`|
71
73
| <aid="itest_service-http_health_check_address"></a>http_health_check_address | If set, the service manager will send an HTTP request to this address to check if the service came up in a healthy state. This check will be retried until it returns a 200 HTTP code. When used in conjunction with autoassigned ports, `$${@@//label/for:service:port_name}` can be used in the address. Example: `http_health_check_address = "http://127.0.0.1:$${@@//label/for:service:port_name}",`| String | optional |`""`|
72
74
| <aid="itest_service-named_ports"></a>named_ports | For each element of the list, the service manager will pick a free port and assign it to the service. The port's fully-qualified name is the service's fully-qualified label and the port name, separated by a colon. For example, a port assigned with `named_ports = ["http_port"]` will be assigned a fully-qualified name of `@@//label/for:service:http_port`.<br><br>Named ports are accessible through the service-port mapping. For more details, see `autoassign_port`. | List of strings | optional |`[]`|
75
+
| <aid="itest_service-shutdown_signal"></a>shutdown_signal | The signal to send to the service when it needs to be shut down. Valid values are: SIGTERM and SIGKILL. SIGTERM is necessary to have proper coverage of services which needs to be gracefully terminated | String | optional |`"SIGTERM"`|
76
+
| <aid="itest_service-shutdown_timeout"></a>shutdown_timeout | The duration to wait after sending the shutdown signal before forcefully killing the service. The syntax is based on common time duration with a number, followed by the time unit. For example, `200ms`, `1s`, `2m`, `3h`, `4d`. | String | optional |`"1s"`|
73
77
| <aid="itest_service-so_reuseport_aware"></a>so_reuseport_aware | If set, the service manager will not release the autoassigned port. The service binary must use SO_REUSEPORT when binding it. This reduces the possibility of port collisions when running many service_tests in parallel, or when code binds port 0 without being aware of the port assignment mechanism.<br><br>Must only be set when `autoassign_port` is enabled or `named_ports` are used. | Boolean | optional |`False`|
This check will be retried until it returns a 200 HTTP code. When used in conjunction with autoassigned ports, `$${@@//label/for:service:port_name}` can be used in the address.
doc="The signal to send to the service when it needs to be shut down. Valid values are: SIGTERM and SIGKILL. SIGTERM is necessary to have proper coverage of services which needs to be gracefully terminated",
286
+
values= ["SIGTERM", "SIGKILL"],
287
+
),
288
+
"shutdown_timeout": attr.label(
289
+
default="//:shutdown_timeout",
290
+
doc="The duration to wait after sending the shutdown signal before forcefully killing the service. The syntax is based on common time duration with a number, followed by the time unit. For example, `200ms`, `1s`, `2m`, `3h`, `4d`.",
291
+
),
292
+
"error_on_forceful_shutdown": attr.label(
293
+
default="//:error_on_forceful_shutdown",
294
+
doc="""If set to True, the service manager will fail the service_test if the service had to be forcefully killed if the signal was not SIGKILL and after the shutdown timeout elapsed.
295
+
296
+
This needs to be False to have coverage of your services but don't want a them to be graceful at shutdown""",
log.Printf("failed to parse health check timeout, falling back to no timeout: %v", err)
248
+
returnerr
249
+
}
250
+
251
+
log.Printf("Sent SIGTERM to %s, waiting for %s to stop gracefully\n", s.Colorize(s.Label), s.VersionedServiceSpec.ShutdownTimeout)
252
+
253
+
waitFor:=time.After(shutdownTimeout)
254
+
for {
255
+
// Check if the process has exited
256
+
ifs.isDone() {
257
+
break
258
+
}
259
+
260
+
select {
261
+
case<-waitFor:
262
+
log.Printf("%s did not exit within %s, sending SIGKILL. If you are trying to collect coverage, you will most likely miss stats, try increasing the shutdown timeout.\n", s.Colorize(s.Label), shutdownTimeout)
0 commit comments