1 // vi: ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2019-2020 Nokia
5 Copyright (c) 2018-2020 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 Mnemonic: test_msg_support.c
23 Abstract: Support for testing with messages; requires RMR defs, so not
24 to be included for things like ring tests etc.
25 Author: E. Scott Daniels
26 Date: 14 April 2020 (AKD)
29 #ifndef _test_msg_support_c
30 #define _test_msg_support_c
39 int test_support_xact_count = 0;
41 Send a 'burst' of messages to drive some send retry failures to increase RMr coverage
42 by handling the retry caee.
44 static void send_n_msgs( void* ctx, int n ) {
45 rmr_mbuf_t* msg; // message buffers
48 msg = rmr_alloc_msg( ctx, 1024 );
50 fprintf( stderr, "<FAIL> mass send of %d messages couldn't allocate message!\n", n );
54 fprintf( stderr, "<INFO> mass send of %d messages\n", n );
55 for( i = 0; i < n; i++ ) {
60 snprintf( msg->xaction, 32, "%015d", test_support_xact_count++ ); // simple transaction id so we can test receive specific and ring stuff
63 msg = rmr_send_msg( ctx, msg );
64 if( msg && msg->state != 0 ) {
65 fprintf( stderr, "<WARN> mass send failed: state=%d type=%d\n", msg->state, msg->mtype );
72 Allow test to reset the transaction id counter.
74 static void reset_xact_count() {
75 test_support_xact_count = 0;
79 Refresh or allocate a message with some default values
81 static rmr_mbuf_t* fresh_msg( void* ctx, rmr_mbuf_t* msg ) {
83 msg = rmr_alloc_msg( ctx, 2048 );