SMC Remote.  Finding a concurrency problem in a simple client-server application.

SMC Remote is a simple socket based client server system.  The system allows users to compile 'SMC' files on a remote server.  The client component is invoked from the command line just like the normal SMC compiler.  However, instead of compiling the .sm file it transmits that file to a server which compiles the file and sends the results back to the client.  The advantage to this is that users of SMCRemote are always using the most current SMC compiler.

I suspect that there is a concurrency problem in the server.  I think that there are some unprotected variables in the server that will get corrupted if two compiles are run simultaneously.  This test is an attempt to demonstrate the problem.

First, we create some common definitions that we'll use throughout the rest of the test.  These definitions include classpaths and commands.

Common Definitions

com.objectmentor.fixtures.CommandLineFixture

definition

SERVERPATH

c:/cygwin/home/administrator/smcRemote/SMCRemoteServer.jar\;c:/jdom-b7/build/jdom.jar\;c:/oreilly/lib/cos.jar

definition

SMCREMOTESERVER

java -classpath SERVERPATH com.objectmentor.SMCRemote.server.SMCRemoteService

definition

CLIENTPATH

c:/cygwin/home/administrator/smcRemote/SMCRemoteClient.jar

definition

SMCREMOTECLIENT

java -classpath CLIENTPATH com.objectmentor.SMCRemote.client.SMCRemoteClient

 

Next we'll test one of the two basic operations of the system -- registration.  The client is invoked to register a new user whose email address is bob@bob.com.  This test makes sure that this new user gets properly registered.  It does this by inspecting the verbose output stream of both the client and the server.  It trusts that if the two output streams say the right things then the user was, in fact, correctly added.  This is a safe assumption because I have plenty of unit tests that show that registration works properly.

Note the command line arguments for the server.  -v causes it to emit verbose output.  -e causes it to use a dummy email sender, so that the user's password will not be emailed to him.  Without this argument, our postmaster gets lots of nasty email messages about unknown users like bob@bob.com

Register a user.

com.objectmentor.fixtures.CommandLineFixture

title

Simple Registration test

 

command

rm -rf users

 

spawn

SMCREMOTESERVER -v -e

server

find

server.stdout

SMCRemoteService

find

server.stdout

0.99

find

server.stdout

port = 9000

command

SMCREMOTECLIENT -v -r bob@bob.com

client1

contains

client1.stdout

Attempting to register bob@bob.com

contains

client1.stdout

bob@bob.com was registered

find

server.stdout

bob@bob.com requests registration

command

rm -rf users

 

 

Next we test whether or not we can do two simultaneous registrations at the same time.  I expect that this will work.

Multiple simultaneous registrations

com.objectmentor.fixtures.CommandLineFixture

title

Multiple registration test

 

spawn

SMCREMOTESERVER -v -e

server

pause

2

 

spawn

SMCREMOTECLIENT -v -r bob1@bob.com

client1

spawn

SMCREMOTECLIENT -v -r bob2@bob.com

client2

waitFor

client1

 

waitFor

client2

 

contains

client1.stdout

bob1@bob.com was registered

contains

client2.stdout

bob2@bob.com was registered

 

Next we run a simple compile.  In order to do this we create a dummy registration file for bill@bill.com.  I can't just register bill@bill.com because the server would generate a random password and email it to bill@bill.com -- which I presume is not a legal email address.  So, instead, I write the XML record for a user in the appropriate file.  Then I create a simple .sm file and run the compiler.  I know it worked if the appropriate result file (F.java) is created.

Simple compile

com.objectmentor.fixtures.CommandLineFixture

title

Simple compile

 

command

rm -f F.java

 

createFile

users/bill@bill.com

<?xml version="1.0" encoding="UTF-8"?>

<user><name>bill@bill.com</name><password>billy</password><loginCount>0</loginCount></user>

spawn

SMCREMOTESERVER -e -v

server

createFile

x.sm

Context c
Initial I
FSMName F
{I {E I A}}

command

SMCREMOTECLIENT -v -u bill@bill.com -w billy x.sm

compile

fileExists

F.java

 

 

Finally I try two compiles at the same time.  I expect that this will fail.

Multiple simultaneous compiles

com.objectmentor.fixtures.CommandLineFixture

title

Multiple compiles

 

command

rm -f F.java

 

command

rm -f G.java

 

createFile

y.sm

Context c
Initial I
FSMName G
{I {E I A}}

spawn

SMCREMOTESERVER -e -v

server

spawn

SMCREMOTECLIENT -v -u bill@bill.com -w billy x.sm

compile1

spawn

SMCREMOTECLIENT -v -u bill@bill.com -w billy y.sm

compile2

waitFor

compile1

 

waitFor

compile2

 

find

compile1.stdout

Compilation results received.

find

compile2.stdout

Compilation results received.

fileExists

F.java

 

fileExists

G.java

 

 

Summary

fit.Summary