@@ -108,8 +108,34 @@ echo -e "${GRN}Testing HEAD:${RST} $(git rev-parse HEAD)"
108108DEFAULT_TIMEOUT_MINUTES=5
109109PROTOCOL_TIMEOUT_MINUTES=45
110110DEFAULT_PROTOCOL_SHARDS=5
111- MIN_PROTOCOL_SHARDS=3
112- MAX_PROTOCOL_SHARDS=5
111+ MIN_PROTOCOL_SHARDS=1
112+ MAX_PROTOCOL_SHARDS=16
113+
114+ resolve_protocol_shards () {
115+ local shards
116+
117+ if [[ -n " ${UNIT_TEST_PROTOCOL_SHARDS} " ]]; then
118+ shards=" ${UNIT_TEST_PROTOCOL_SHARDS} "
119+ else
120+ shards=" $( nproc 2> /dev/null || echo " ${DEFAULT_PROTOCOL_SHARDS} " ) "
121+ echo -e " ${GRN} Protocol shards:${RST} auto-detected ${shards} from nproc (override with UNIT_TEST_PROTOCOL_SHARDS)" >&2
122+ fi
123+
124+ if ! [[ " ${shards} " =~ ^[0-9]+$ ]]; then
125+ echo -e " ${YLW} Invalid UNIT_TEST_PROTOCOL_SHARDS='${shards} ', using ${DEFAULT_PROTOCOL_SHARDS}${RST} " >&2
126+ shards=" ${DEFAULT_PROTOCOL_SHARDS} "
127+ fi
128+ if [[ " ${shards} " -lt " ${MIN_PROTOCOL_SHARDS} " ]]; then
129+ echo -e " ${YLW} Protocol shards=${shards} is too low, clamping to ${MIN_PROTOCOL_SHARDS}${RST} " >&2
130+ shards=" ${MIN_PROTOCOL_SHARDS} "
131+ fi
132+ if [[ " ${shards} " -gt " ${MAX_PROTOCOL_SHARDS} " ]]; then
133+ echo -e " ${YLW} Protocol shards=${shards} is too high, clamping to ${MAX_PROTOCOL_SHARDS}${RST} " >&2
134+ shards=" ${MAX_PROTOCOL_SHARDS} "
135+ fi
136+
137+ echo " ${shards} "
138+ }
113139
114140HAS_PROTOCOL_PACKAGE=true
115141if [[ $( echo " ${UNIT_TEST_PACKAGES} " | grep -E ' \s?\S+protocol\s+' ) == " " ]]; then
@@ -129,19 +155,7 @@ else
129155 bg_pids+=(" $! " )
130156
131157 if [[ $UNIT_TEST_COUNT -eq 1 ]]; then
132- protocol_shards=" ${UNIT_TEST_PROTOCOL_SHARDS:- ${DEFAULT_PROTOCOL_SHARDS} } "
133- if ! [[ " ${protocol_shards} " =~ ^[0-9]+$ ]]; then
134- echo -e " ${YLW} Invalid UNIT_TEST_PROTOCOL_SHARDS='${protocol_shards} ', using default ${DEFAULT_PROTOCOL_SHARDS}${RST} "
135- protocol_shards=" ${DEFAULT_PROTOCOL_SHARDS} "
136- fi
137- if [[ " ${protocol_shards} " -lt " ${MIN_PROTOCOL_SHARDS} " ]]; then
138- echo -e " ${YLW} UNIT_TEST_PROTOCOL_SHARDS=${protocol_shards} is too low, clamping to ${MIN_PROTOCOL_SHARDS}${RST} "
139- protocol_shards=" ${MIN_PROTOCOL_SHARDS} "
140- fi
141- if [[ " ${protocol_shards} " -gt " ${MAX_PROTOCOL_SHARDS} " ]]; then
142- echo -e " ${YLW} UNIT_TEST_PROTOCOL_SHARDS=${protocol_shards} is too high, clamping to ${MAX_PROTOCOL_SHARDS}${RST} "
143- protocol_shards=" ${MAX_PROTOCOL_SHARDS} "
144- fi
158+ protocol_shards=" $( resolve_protocol_shards) "
145159
146160 protocol_list_cmd=(go test -list ' ^Test' )
147161 if [[ -n " ${BUILD_TAGS} " ]]; then
0 commit comments