Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief This is ultra high survival test case. We kill the tmsrv/tmqueue
0003  *  periodically, and also periodically disk fails to log the prepared status.
0004  *  Test performs self looping i.e. try to forward to non existing service
0005  *  and put msg back on queue - the same queue is errorq.
0006  * @file crashloop.c
0007  */
0008 /* -----------------------------------------------------------------------------
0009  * Enduro/X Middleware Platform for Distributed Transaction Processing
0010  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0011  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0012  * This software is released under one of the following licenses:
0013  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0014  * See LICENSE file for full text.
0015  * -----------------------------------------------------------------------------
0016  * AGPL license:
0017  *
0018  * This program is free software; you can redistribute it and/or modify it under
0019  * the terms of the GNU Affero General Public License, version 3 as published
0020  * by the Free Software Foundation;
0021  *
0022  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0023  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0024  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0025  * for more details.
0026  *
0027  * You should have received a copy of the GNU Affero General Public License along 
0028  * with this program; if not, write to the Free Software Foundation, Inc.,
0029  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030  *
0031  * -----------------------------------------------------------------------------
0032  * A commercial use license is available from Mavimax, Ltd
0033  * contact@mavimax.com
0034  * -----------------------------------------------------------------------------
0035  */
0036 #include <string.h>
0037 #include <stdio.h>
0038 #include <stdlib.h>
0039 #include <memory.h>
0040 #include <unistd.h>
0041 
0042 #include <atmi.h>
0043 #include <ubf.h>
0044 #include <ndebug.h>
0045 #include <test.fd.h>
0046 #include <ndrstandard.h>
0047 #include <ubfutil.h>
0048 #include <nstopwatch.h>
0049 #include <nstdutil.h>
0050 #include <exassert.h>
0051 /*---------------------------Externs------------------------------------*/
0052 /*---------------------------Macros-------------------------------------*/
0053 /*---------------------------Enums--------------------------------------*/
0054 /*---------------------------Typedefs-----------------------------------*/
0055 /** verify matching req/replies. */
0056 typedef struct 
0057 {
0058     int num_req;
0059 } test_result_t;
0060 
0061 /*---------------------------Globals------------------------------------*/
0062 /*---------------------------Statics------------------------------------*/
0063 /*---------------------------Prototypes---------------------------------*/
0064 
0065 #define MAX_TEST    100
0066 
0067 /**
0068  * Crashloop test
0069  * @param qname queue name for crash loop
0070  * @return EXSUCCEED/EXFAIL
0071  */
0072 expublic int basic_crashloop(char *qname)
0073 {
0074     int ret = EXSUCCEED;
0075     TPQCTL qc;
0076     long i;
0077     long olen;
0078     char tmpbuf[1024];
0079     long num;
0080     UBFH *p_ub = NULL;
0081     test_result_t rsp[MAX_TEST];
0082     char cmd[PATH_MAX+1];
0083     /* run test for 10 min... */
0084     ndrx_stopwatch_t w;
0085     
0086     NDRX_LOG(log_error, "case basic_crashloop");
0087     
0088     memset(rsp, 0, sizeof(rsp));
0089     
0090     NDRX_ASSERT_TP_OUT((NULL!=(p_ub=(UBFH *)tpalloc("UBF", NULL, 1024))), "Failed to alloc");
0091     
0092     for (i=0; i<MAX_TEST; i++)
0093     {
0094         NDRX_ASSERT_UBF_OUT( (EXSUCCEED==Bchg(p_ub, T_LONG_FLD, 0, (char *)&i, 0L)), 
0095                 "Failed to set test num");
0096         
0097         NDRX_ASSERT_UBF_OUT( (EXSUCCEED==Bchg(p_ub, T_STRING_FLD, 0, "REQ", 0L)), 
0098                 "Failed to set test str");
0099         
0100         /* enq */
0101         memset(&qc, 0, sizeof(qc));
0102         
0103         NDRX_ASSERT_TP_OUT((EXSUCCEED==tpenqueue("MYSPACE", qname, &qc, 
0104                 (char *)p_ub, 0, 0L)), "Failed to enq");
0105     }
0106     
0107     
0108     ndrx_stopwatch_reset(&w);
0109     
0110     do
0111     {
0112         /* logging fails:*/
0113         NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin lcf tcrash -n -A 150 -a"), "system() failed");
0114         sleep(2);
0115         
0116         /* crash the tmsrv: */
0117         NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin killall tmqueue tmsrv"), "system() failed");
0118         sleep(10);
0119         
0120         /* restore disk operations */
0121         NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin lcf tcrash -n -A 0 -a"), "system() failed");
0122         sleep(10);
0123         
0124         /* crash tmsrv again: */
0125         NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin killall tmqueue tmsrv"), "system() failed");
0126         sleep(10);
0127         /* run test for 5 min... */
0128     } while (ndrx_stopwatch_get_delta_sec(&w) < 300);
0129     
0130     /* disable autoQ so that we can read results,  restart q if any parked msgs.. */
0131     NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin killall tmqueue"), "system() failed");
0132 
0133     /* let tmqueue to boot back: */
0134     sleep(10);
0135     snprintf(cmd, sizeof(cmd), "xadmin mqch -n1 -i 100 -q%s,autoq=n", qname);
0136     NDRX_LOG(log_error, "%s", cmd);
0137     NDRX_ASSERT_VAL_OUT(EXSUCCEED==system(cmd), "system() failed");
0138     
0139     NDRX_LOG(log_error, "xadmin mqlc");
0140     NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin mqlc"), "system() failed");
0141     
0142     /* Wait messages to settle down */
0143     sleep(60);
0144     
0145     /* print some statistics.. */
0146     NDRX_LOG(log_error, "xadmin pt");
0147     NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin pt"), "system() failed");
0148     NDRX_LOG(log_error, "xadmin mqlq");
0149     NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin mqlq"), "system() failed");
0150     
0151     /* read & match results, all msgs should be in place */
0152     
0153     for (i=0; i<MAX_TEST; i++)
0154     {
0155         memset(&qc, 0, sizeof(qc));
0156         
0157         tpfree((char *)p_ub);
0158         p_ub = NULL;
0159         
0160         /* verify req */
0161         NDRX_ASSERT_TP_OUT((EXSUCCEED==tpdequeue("MYSPACE", qname, &qc, (char **)&p_ub, &olen, 0)), 
0162                 "Must be OK at loop %ld", i);
0163         
0164         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_FLD, 0, tmpbuf, NULL)), 
0165                 "Failed to get data fld");
0166         NDRX_ASSERT_VAL_OUT(0==strcmp(tmpbuf, "REQ"), "Request not found: %s", tmpbuf);
0167         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_LONG_FLD, 0, (char *)&num, NULL)), 
0168                 "Failed to get num");
0169         rsp[num].num_req++;
0170                 
0171     }
0172     
0173     /* no any extra msgs... */
0174     memset(&qc, 0, sizeof(qc));
0175     NDRX_ASSERT_TP_OUT((EXFAIL==tpdequeue("MYSPACE", qname, &qc, (char **)&p_ub, &olen, 0)), 
0176                 "Must fail!");
0177     NDRX_ASSERT_VAL_OUT((QMENOMSG==qc.diagnostic), "Invalid diagnostics code: %ld", qc.diagnostic);
0178     
0179     /* verify that all msgs as been set... */
0180     for (i=0; i<MAX_TEST; i++)
0181     {
0182         NDRX_ASSERT_VAL_OUT(rsp[i].num_req==1, "Invalid num_req at %ld: %d", 
0183                 i, rsp[i].num_req);
0184     }
0185     
0186 out:
0187 
0188     NDRX_LOG(log_error, "xadmin pt (exit)");
0189     NDRX_ASSERT_VAL_OUT(EXSUCCEED==system("xadmin pt"), "system() failed");
0190     if (EXSUCCEED!=tpterm())
0191     {
0192         NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
0193         ret=EXFAIL;
0194         goto out;
0195     }
0196 
0197     if (NULL!=p_ub)
0198     {
0199         tpfree((char *)p_ub);
0200     }
0201 
0202     return ret;
0203 }
0204 
0205 /* vim: set ts=4 sw=4 et smartindent: */