tags:

views:

26

answers:

1

I'm trying to get a Session Timeout when I call on a certain Stored Procedures in my DB (the return code for this in my DB is 3). I wanna do that so that I can make a successful Assertion to my DB. I tried putting the thread to sleep for a couple of minutes but I'm sure there is a more practical (faster) way to get a Session Timeout error.

The following code is to assert an "Invalid Session" return code (that is 2) I wanna do something similar to get a 3 (Session timeout) as a return code.

    [Test, Description("Tests Possible Return Codes for the AcquireChangeLock SP")]
    public void test_invalidSession()
    {
        //Method to generate a valid Session Id
        int sessionId = src.run_Session_Logon_SP(dataSource, initialCataloge);

        //Generate a random no. and add it to the
        //retrieved sessionId to get an invalid sessionId
        Guid screw = Guid.NewGuid();
        byte[] _bytes = screw.ToByteArray();
        int k = ((int)_bytes[0]) | ((int)_bytes[1] << 8) | ((int)_bytes[2]);
        sessionId += k;

        //List with all the Tables and their Guids in the DB
        lst_objectName_Guid = src.getObjectName_Guid(direct);
        for (int i = 0; i < lst_objectName_Guid.Count; i += 2)
        {
            objectName = lst_objectName_Guid[i];            //Get the objectName values from the Even Indexes
            oGuid = lst_objectName_Guid[i + 1];            //Get the Guid valuees from the Odd Indexes
            final_oGuid = new Guid(oGuid);

            Console.WriteLine(objectName);

            //Method that generate Return Codes
            int code = src.run_AcquireChangeLock_SP(dataSource, initialCataloge, sessionId, objectName, final_oGuid);
            Assert.AreEqual(2, code);
            src.run_ReleaseChangeLock_SP(dataSource, initialCataloge, sessionId, objectName, final_oGuid);
        }
    }
A: 

You could add a WAITFOR to the start of your stored procedure:

-- Wait for thirty seconds...
WAITFOR DELAY '00:30'
Mitch Wheat
No I don't want to change the SP 'cause I wanna make other tests on it. What I want is to cause a Timeout in my code
Reda
@Reda: if you put a timeout in your code, you won't necessarily be testing the same code path as your SP timing out...
Mitch Wheat
@Mitch: What I want is for the DB to return a '3' code (timeout) and to do that I must call on (any) SP but this call should take enough time to cause a timeout and so the DB will return the correct code
Reda