Friday, November 03, 2006

Running Concurrency Tests

Starting concurrency tests simultaneously could be tricky, especially they need to start at the same time from different workstations.

One way to do it:

CREATE TABLE WhistleSound(i INT)
go
CREATE PROCEDURE WaitForWhistle
AS
DECLARE @cnt INT
SET @cnt = 0
WHILE (@cnt = 0) BEGIN
SELECT @cnt = COUNT(*) FROM WhistleSound WITH(NOLOCK)
IF @cnt = 0
WAITFOR DELAY '00:00:01'
END
go
CREATE PROCEDURE BlowWhistle
AS
INSERT WhistleSound(i) VALUES(1)
go

From one connection run

DELETE FROM WhistleSound
SELECT Getdate()
EXEC WaitForWhistle
SELECT Getdate()

From another connection run

SELECT Getdate()
EXEC WaitForWhistle
SELECT Getdate()

From third connection run

EXEC dbo.BlowWhistle

0 Comments:

Post a Comment

<< Home