I use JMeter to test my web application. and my test case is to add a record in database. and then I set the "number of thread user" to 20, it means that it will simulate 20 users work at the same time. and then I run the test case. But finally i found the system didn t create 20 records in database, but instead just create 13 records in database.
I want to know why this happened ? Is it possible that because in my web application i didn t add a "synchronized" in front of the add records method ? I used linq, If two user post a request to create a record to server at the same time, what will happen? Just create a record or can successfully create two records, or unknown ?
Following is the sample code for create a record in database:
public int SaveEventGroup(int id, Models.Entities.EventGroup e, Nullable<int> setpublish)
{
try
{
Entities.EventGroup db;
if (id == 0)
{
db = new Entities.EventGroup();
db.CreatedBy = e.CreatedBy;
db.CreateDatetime = DateTime.Now;
db.Status = true;
}
else
{
db = this.GetEventGroup(id);
}
db.NameCN = e.NameCN;
db.NameEN = e.NameEN;
db.NameZH = e.NameZH;
db.NamePT = e.NamePT;
db.DisplayOrder = GetGroupMaxDisplayOrder() + 1;
if (setpublish == null)
{
db.PublishStatus = false;
db.PublishDatetime = null;
db.UpdateDatetime = DateTime.Now;
db.UpdatedBy = e.UpdatedBy;
}
if (id == 0)
dataContext.AddToEventGroupSet(db);
dataContext.SaveChanges();
return db.Id;
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
throw ex;
}
}