add test case where (fake) sms messages never arrive

This commit is contained in:
Eric House 2018-07-14 15:43:42 -07:00
parent 352d87a327
commit 2d8ac995b7
4 changed files with 62 additions and 44 deletions

View file

@ -639,6 +639,7 @@ typedef enum {
,CMD_DROPSENDRELAY
,CMD_DROPRCVRELAY
,CMD_DROPSENDSMS
,CMD_SMSFAILPCT
,CMD_DROPRCVSMS
,CMD_FORCECHANNEL
@ -762,6 +763,7 @@ static CmdInfoRec CmdInfoRecs[] = {
,{ CMD_DROPSENDRELAY, false, "drop-send-relay", "start new games with relay send disabled" }
,{ CMD_DROPRCVRELAY, false, "drop-receive-relay", "start new games with relay receive disabled" }
,{ CMD_DROPSENDSMS, false, "drop-send-sms", "start new games with sms send disabled" }
,{ CMD_SMSFAILPCT, true, "sms-fail-pct", "percent of sms sends, randomly chosen, never arrive" }
,{ CMD_DROPRCVSMS, false, "drop-receive-sms", "start new games with sms receive disabled" }
,{ CMD_FORCECHANNEL, true, "force-channel", "force (clients) to use this hostid/channel" }
@ -2445,6 +2447,10 @@ main( int argc, char** argv )
case CMD_DROPSENDSMS:
mainParams.commsDisableds[COMMS_CONN_SMS][1] = XP_TRUE;
break;
case CMD_SMSFAILPCT:
mainParams.smsSendFailPct = atoi(optarg);
XP_ASSERT( mainParams.smsSendFailPct >= 0 && mainParams.smsSendFailPct <= 100 );
break;
case CMD_DROPRCVSMS:
mainParams.commsDisableds[COMMS_CONN_SMS][0] = XP_TRUE;
break;

View file

@ -114,15 +114,24 @@ unlock_queue( LinSMSData* storage )
}
static XP_S16
send_sms( LinSMSData* storage, XWStreamCtxt* stream,
write_fake_sms( LaunchParams* params, XWStreamCtxt* stream,
const XP_UCHAR* phone, XP_U16 port )
{
XP_S16 nSent;
XP_U16 pct = XP_RANDOM() % 100;
XP_Bool skipWrite = pct < params->smsSendFailPct;
if ( skipWrite ) {
nSent = stream_getSize( stream );
XP_LOGF( "%s(): dropping sms msg of len %d to phone %s", __func__,
nSent, phone );
} else {
LinSMSData* storage = getStorage( params );
const XP_U8* buf = stream_getPtr( stream );
XP_U16 buflen = stream_getSize( stream );
XP_LOGF( "%s(phone=%s, port=%d, len=%d)", __func__, phone,
port, buflen );
XP_S16 nSent = -1;
XP_ASSERT( !!storage );
char path[256];
@ -170,8 +179,9 @@ send_sms( LinSMSData* storage, XWStreamCtxt* stream,
nSent = buflen;
LOG_RETURNF( "%d", nSent );
}
return nSent;
} /* linux_sms_send */
} /* write_fake_sms */
static XP_S16
decodeAndDelete( LinSMSData* storage, const gchar* name,
@ -350,8 +360,7 @@ linux_sms_invite( LaunchParams* params, const CurGameInfo* gi,
addrToStream( stream, addr );
LinSMSData* storage = getStorage( params );
send_sms( storage, stream, toPhone, toPort );
write_fake_sms( params, stream, toPhone, toPort );
stream_destroy( stream );
}
@ -381,8 +390,7 @@ doSend( LaunchParams* params, const XP_U8* buf,
stream_putU32( stream, gameID );
stream_putBytes( stream, buf, buflen );
LinSMSData* storage = getStorage( params );
(void)send_sms( storage, stream, phone, port );
(void)write_fake_sms( params, stream, phone, port );
stream_destroy( stream );
}

View file

@ -59,6 +59,7 @@ typedef struct LaunchParams {
char* dbName;
sqlite3* pDb; /* null unless opened */
XP_U16 saveFailPct;
XP_U16 smsSendFailPct;
const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS];
#ifdef USE_SQLITE
char* dbFileName;

View file

@ -393,6 +393,8 @@ def build_cmds(args):
PARAMS += ['--use-udp']
if args.ADD_SMS:
PARAMS += [ '--sms-number', PHONE_BASE + str(DEV - 1) ]
if args.SMS_FAIL_PCT > 0:
PARAMS += [ '--sms-fail-pct', args.SMS_FAIL_PCT ]
if DEV > 1:
PARAMS += [ '--server-sms-number', PHONE_BASE + '0' ]
@ -655,6 +657,7 @@ def mkParser():
parser.add_argument('--trade-pct', dest = 'TRADE_PCT', default = 0, type = int)
parser.add_argument('--add-sms', dest = 'ADD_SMS', default = False, action = 'store_true')
parser.add_argument('--sms-fail-pct', dest = 'SMS_FAIL_PCT', default = 0, type = int)
parser.add_argument('--remove-relay', dest = 'ADD_RELAY', default = True, action = 'store_false')
parser.add_argument('--with-valgrind', dest = 'VALGRIND', default = False,