Skip to content

Commit cde4dfc

Browse files
committed
fix failing tests
1 parent bd333ab commit cde4dfc

3 files changed

Lines changed: 64 additions & 23 deletions

File tree

src/EFCore.SingleStore/Storage/Internal/SingleStoreConnectionStringOptionsValidator.cs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ public virtual bool EnsureMandatoryOptions(ref string connectionString)
1717
if (connectionString is not null)
1818
{
1919
var csb = new SingleStoreConnectionStringBuilder(connectionString);
20-
AddConnectionAttributes(csb);
20+
21+
var attrsChanged = AddConnectionAttributes(csb);
22+
var flagsChanged = false;
2123

2224
if (!ValidateMandatoryOptions(csb))
2325
{
2426
csb.AllowUserVariables = true;
2527
csb.UseAffectedRows = false;
28+
flagsChanged = true;
29+
}
2630

31+
if (attrsChanged || flagsChanged)
32+
{
2733
connectionString = csb.ConnectionString;
28-
2934
return true;
3035
}
3136
}
@@ -38,17 +43,22 @@ public virtual bool EnsureMandatoryOptions(DbConnection connection)
3843
if (connection is not null)
3944
{
4045
var csb = new SingleStoreConnectionStringBuilder(connection.ConnectionString);
41-
AddConnectionAttributes(csb);
46+
47+
var attrsChanged = AddConnectionAttributes(csb);
48+
var flagsChanged = false;
4249

4350
if (!ValidateMandatoryOptions(csb))
51+
{
52+
csb.AllowUserVariables = true;
53+
csb.UseAffectedRows = false;
54+
flagsChanged = true;
55+
}
56+
57+
if (attrsChanged || flagsChanged)
4458
{
4559
try
4660
{
47-
csb.AllowUserVariables = true;
48-
csb.UseAffectedRows = false;
49-
5061
connection.ConnectionString = csb.ConnectionString;
51-
5262
return true;
5363
}
5464
catch (Exception e)
@@ -69,37 +79,38 @@ public virtual bool EnsureMandatoryOptions(DbDataSource dataSource)
6979
}
7080

7181
var csb = new SingleStoreConnectionStringBuilder(dataSource.ConnectionString);
72-
AddConnectionAttributes(csb);
7382

83+
// We can’t persist ConnectionAttributes changes back to the data source, so don’t attempt.
7484
if (!ValidateMandatoryOptions(csb))
7585
{
76-
// We can't alter the connection string of a DbDataSource/SingleStoreDataSource as we do for DbConnection/SingleStoreConnection in cases
77-
// where the necessary connection string options have not been set.
78-
// We can only throw.
7986
ThrowException();
8087
}
8188

8289
return true;
8390
}
8491

85-
static void AddConnectionAttributes(SingleStoreConnectionStringBuilder csb)
92+
static bool AddConnectionAttributes(SingleStoreConnectionStringBuilder csb)
8693
{
8794
var existing = csb.ConnectionAttributes?.TrimEnd(',') ?? "";
8895

89-
var programVersion = Assembly.GetExecutingAssembly().GetName().Version;
90-
var connAttrs = $"_connector_name:SingleStore Entity Framework Core provider,_connector_version:{programVersion}";
91-
92-
var existingConnAttrs = existing
96+
var existingAttrs = existing
9397
.Split(',', StringSplitOptions.RemoveEmptyEntries)
9498
.Select(attr => attr.Trim())
99+
.Where(attr => !string.IsNullOrEmpty(attr))
95100
.ToHashSet(StringComparer.OrdinalIgnoreCase);
96101

97-
if (!existingConnAttrs.Contains(connAttrs))
102+
var programVersion = typeof(SingleStoreConnectionStringOptionsValidator).Assembly.GetName().Version;
103+
var nameAttr = "_connector_name:SingleStore Entity Framework Core provider";
104+
var versionAttr = $"_connector_version:{programVersion}";
105+
106+
var changed = existingAttrs.Add(nameAttr) | existingAttrs.Add(versionAttr);
107+
108+
if (changed)
98109
{
99-
csb.ConnectionAttributes = string.IsNullOrEmpty(existing)
100-
? connAttrs
101-
: $"{existing},{connAttrs}";
110+
csb.ConnectionAttributes = string.Join(",", existingAttrs);
102111
}
112+
113+
return changed;
103114
}
104115

105116
public virtual void ThrowException(Exception innerException = null)

test/EFCore.SingleStore.FunctionalTests/Query/TPHInheritanceQuerySingleStoreTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Threading.Tasks;
2+
using EntityFrameworkCore.SingleStore.Tests;
13
using Microsoft.EntityFrameworkCore.Query;
24
using Xunit;
35
using Xunit.Abstractions;
@@ -16,4 +18,31 @@ public override void Setting_foreign_key_to_a_different_type_throws()
1618
{
1719
base.Setting_foreign_key_to_a_different_type_throws();
1820
}
21+
22+
[ConditionalTheory]
23+
[MemberData(nameof(IsAsyncData))]
24+
public override Task Can_include_prey(bool async)
25+
{
26+
// Skipping this test when running on Managed Service due to the specifics of
27+
// how AUTO_INCREMENT works (https://docs.singlestore.com/cloud/reference/sql-reference/data-definition-language-ddl/create-table/#auto-increment-behavior)
28+
if (AppConfig.ManagedService)
29+
{
30+
return Task.CompletedTask;
31+
}
32+
33+
return base.Can_include_prey(async);
34+
}
35+
36+
[ConditionalFact]
37+
public override void Can_insert_update_delete()
38+
{
39+
// Skipping this test when running on Managed Service due to the specifics of
40+
// how AUTO_INCREMENT works (https://docs.singlestore.com/cloud/reference/sql-reference/data-definition-language-ddl/create-table/#auto-increment-behavior)
41+
if (AppConfig.ManagedService)
42+
{
43+
return;
44+
}
45+
46+
base.Can_insert_update_delete();
47+
}
1948
}

test/EFCore.SingleStore.FunctionalTests/SingleStoreConnectionStringOptionsValidatorTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void EnsureMandatoryOptions_AppendsConnectionAttributesWithoutRemovingExi
3131

3232
Assert.Contains("foo:bar", parts);
3333
Assert.Contains("baz:qux", parts);
34-
var programVersion = Assembly.GetExecutingAssembly().GetName().Version;
34+
var programVersion = typeof(SingleStoreConnectionStringOptionsValidator).Assembly.GetName().Version;
3535
Assert.Contains(parts, p => p.StartsWith("_connector_name:SingleStore Entity Framework Core provider"));
3636
Assert.Contains(parts, p => p.StartsWith($"_connector_version:{programVersion}"));
3737
}
@@ -44,7 +44,8 @@ public void EnsureMandatoryOptions_DoesNotDuplicateConnectionAttributes_OnRepeat
4444
Assert.True(_validator.EnsureMandatoryOptions(ref cs));
4545
Assert.False(_validator.EnsureMandatoryOptions(ref cs));
4646

47-
var programVersion = Assembly.GetExecutingAssembly().GetName().Version;
47+
var programVersion = typeof(SingleStoreConnectionStringOptionsValidator).Assembly.GetName().Version;
48+
4849
var parts = new SingleStoreConnectionStringBuilder(cs)
4950
.ConnectionAttributes
5051
.TrimEnd(',')
@@ -86,7 +87,7 @@ public void EnsureMandatoryOptions_DbConnection_InjectsAttributesAndFlags()
8687
Assert.True(result.AllowUserVariables);
8788
Assert.False(result.UseAffectedRows);
8889
Assert.Contains("_connector_name:SingleStore Entity Framework Core provider", result.ConnectionAttributes);
89-
var programVersion = Assembly.GetExecutingAssembly().GetName().Version;
90+
var programVersion = typeof(SingleStoreConnectionStringOptionsValidator).Assembly.GetName().Version;
9091
Assert.Contains($"_connector_version:{programVersion}", result.ConnectionAttributes);
9192
}
9293

0 commit comments

Comments
 (0)