Skip to content

Commit

Permalink
RavenDB-21233: modified test to run faster, changed to using 'Disable…
Browse files Browse the repository at this point in the history
…MaxStatements',formatting
  • Loading branch information
TheGoldenPlatypus committed Nov 28, 2023
1 parent 4384805 commit 2375d09
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Raven.Server/Documents/CollectionRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Task<IOperationResult> ExecutePatch(string collectionName, long start, lo
BlittableJsonReaderObject patchArgs, Action<IOperationProgress> onProgress, OperationCancelToken token)
{
return ExecuteOperation(collectionName, start, take, options, Context, onProgress,
key => new PatchDocumentCommand(Context, key, expectedChangeVector: null, skipPatchIfChangeVectorMismatch: false, patch: (patch, patchArgs), patchIfMissing: (null, null), createIfMissing: null, Database, isTest: false, debugMode: false, collectResultsNeeded: false, returnDocument: false,options.IgnoreMaxStepsForScript), token);
key => new PatchDocumentCommand(Context, key, expectedChangeVector: null, skipPatchIfChangeVectorMismatch: false, patch: (patch, patchArgs), patchIfMissing: (null, null), createIfMissing: null, Database, isTest: false, debugMode: false, collectResultsNeeded: false, returnDocument: false, options.IgnoreMaxStepsForScript), token);
}

protected async Task<IOperationResult> ExecuteOperation(string collectionName, long start, long take, CollectionOperationOptions options, DocumentsOperationContext context,
Expand Down
4 changes: 2 additions & 2 deletions src/Raven.Server/Documents/Patch/PatchDocumentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public PatchDocumentCommand(
bool debugMode,
bool collectResultsNeeded,
bool returnDocument,
bool ignoreMaxStepsForScript =false) : base(context, skipPatchIfChangeVectorMismatch, patch, patchIfMissing, createIfMissing, database, isTest, debugMode, collectResultsNeeded, returnDocument)
bool ignoreMaxStepsForScript = false) : base(context, skipPatchIfChangeVectorMismatch, patch, patchIfMissing, createIfMissing, database, isTest, debugMode, collectResultsNeeded, returnDocument)
{
_id = id;
_expectedChangeVector = expectedChangeVector;
Expand All @@ -469,7 +469,7 @@ protected override long ExecuteCmd(DocumentsOperationContext context)
try
{
if (_ignoreMaxStepsForScript)
run.ScriptEngine.ChangeMaxStatements(int.MaxValue);
run.ScriptEngine.DisableMaxStatements();

using (_patchIfMissing.Run != null ? _database.Scripts.GetScriptRunner(_patchIfMissing.Run, readOnly: false, out runIfMissing) : (IDisposable)null)
{
Expand Down
17 changes: 11 additions & 6 deletions test/SlowTests/Issues/RavenDB_21233.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Raven.Client.Documents.Operations;
using Raven.Client.Documents.Operations.Indexes;
using Raven.Client.Documents.Queries;
using Raven.Server.Config;
using Tests.Infrastructure;
using Xunit;

Expand All @@ -20,7 +21,7 @@ public class RavenDB_21233 : RavenTestBase
{
Query = @"
from ""Orders"" update {
for (var i = 0; i < 10000; i++){
for (var i = 0; i < 100; i++){
this.Freight = 13;
}
}"
Expand All @@ -31,7 +32,7 @@ public class RavenDB_21233 : RavenTestBase
Query = @"
from index ""Orders/ByCompany""
update {
for (var i = 0; i < 10000; i++){
for (var i = 0; i < 100; i++){
this.Total = 0;
}
}"
Expand All @@ -56,13 +57,17 @@ public RavenDB_21233(ITestOutputHelper output) : base(output)
{
}

[Fact]
[RavenFact(RavenTestCategory.Patching)]
public async Task ExecutePatchScriptShouldRespectIgnoreMaxStepsForScriptFlag()
{
Operation operation;
QueryOperationOptions options = new();

using (var store = GetDocumentStore())
using (var store = GetDocumentStore(new Options
{
ModifyDatabaseRecord = record =>
record.Settings[RavenConfiguration.GetKey(x => x.Patching.MaxStepsForScript)] = "100"
}))
{

await store.Maintenance.SendAsync(new CreateSampleDataOperation());
Expand Down Expand Up @@ -91,7 +96,7 @@ public async Task ExecutePatchScriptShouldRespectIgnoreMaxStepsForScriptFlag()
});

Assert.Contains(
"The maximum number of statements executed have been reached - 10000. You can configure it by modifying the configuration option: 'Patching.MaxStepsForScript'.",
"The maximum number of statements executed have been reached - 100. You can configure it by modifying the configuration option: 'Patching.MaxStepsForScript'.",
exception.ToString());


Expand Down Expand Up @@ -124,7 +129,7 @@ public async Task ExecutePatchScriptShouldRespectIgnoreMaxStepsForScriptFlag()
});

Assert.Contains(
"The maximum number of statements executed have been reached - 10000. You can configure it by modifying the configuration option: 'Patching.MaxStepsForScript'.",
"The maximum number of statements executed have been reached - 100. You can configure it by modifying the configuration option: 'Patching.MaxStepsForScript'.",
exception2.ToString());
}
}
Expand Down

0 comments on commit 2375d09

Please sign in to comment.