Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa committed Aug 29, 2024
1 parent bb4eb7b commit 1655d9e
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ static async Task InvalidConnectionTaskAsync(string connectionString, int times)
{
// intentionally not using await so the connection
// will be disposed with invalid underlying session
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
conn.OpenAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
};
// wait 100ms each time so the invalid sessions are generated
// roughly at the same speed as connections for query tasks
Expand Down
4 changes: 4 additions & 0 deletions Snowflake.Data.Tests/Mock/MockRetryUntilRestTimeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
_forceTimeoutForNonLoginRequestsOnly && !message.RequestUri.AbsolutePath.Equals(RestPath.SF_LOGIN_PATH))
{
// Override the http timeout and set to 1ms to force all http request to timeout and retry
// Disable warning as this is the way to be compliant with netstandard2.0
// API reference: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage?view=netstandard-2.0
#pragma warning disable CS0618 // Type or member is obsolete
message.Properties[BaseRestRequest.HTTP_REQUEST_TIMEOUT_KEY] = TimeSpan.FromTicks(0);
#pragma warning restore CS0618 // Type or member is obsolete
}

return await (base.SendAsync(message, restTimeout, externalCancellationToken).ConfigureAwait(false));
Expand Down
79 changes: 41 additions & 38 deletions Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ArrowResultChunkTest
internal static readonly RecordBatch RecordBatchWithNullValue = new RecordBatch.Builder()
.Append("Col_Int32", false, col => col.Int32(array => array.AppendNull()))
.Build();

[Test]
public void TestResultFormatIsArrow()
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public void TestNextReturnsFalseIfNoData()
public void TestNextIteratesThroughAllRecordsOfOneBatch()
{
var chunk = new ArrowResultChunk(_recordBatchOne);

for (var i = 0; i < RowCountBatchOne; ++i)
{
Assert.IsTrue(chunk.Next());
Expand All @@ -72,7 +72,7 @@ public void TestNextIteratesThroughAllRecordsOfTwoBatches()
{
var chunk = new ArrowResultChunk(_recordBatchOne);
chunk.AddRecordBatch(_recordBatchTwo);

for (var i = 0; i < RowCountBatchOne + RowCountBatchTwo; ++i)
{
Assert.IsTrue(chunk.Next());
Expand All @@ -87,30 +87,30 @@ public void TestRewindIteratesThroughAllRecordsOfBatchOne()

// move to the end of the batch
while (chunk.Next()) {}

for (var i = 0; i < RowCountBatchOne; ++i)
{
Assert.IsTrue(chunk.Rewind());
}
Assert.IsFalse(chunk.Rewind());
}

[Test]
public void TestRewindIteratesThroughAllRecordsOfTwoBatches()
{
var chunk = new ArrowResultChunk(_recordBatchOne);
chunk.AddRecordBatch(_recordBatchTwo);

// move to the end of the batch
while (chunk.Next()) {}

for (var i = 0; i < RowCountBatchOne + RowCountBatchTwo; ++i)
{
Assert.IsTrue(chunk.Rewind());
}
Assert.IsFalse(chunk.Rewind());
}

[Test]
public void TestResetClearsChunkData()
{
Expand All @@ -121,14 +121,14 @@ public void TestResetClearsChunkData()
rowCount = 2
};
var chunk = new ArrowResultChunk(_recordBatchOne);

chunk.Reset(chunkInfo, 0);

Assert.AreEqual(0, chunk.ChunkIndex);
Assert.AreEqual(chunkInfo.url, chunk.Url);
Assert.AreEqual(chunkInfo.rowCount, chunk.RowCount);
}

[Test]
public void TestRowCountReturnsNumberOfRows()
{
Expand All @@ -144,16 +144,19 @@ public void TestGetChunkIndexReturnsFirstChunk()

Assert.AreEqual(-1, chunk.ChunkIndex);
}

[Test]
public void TestUnusedExtractCellThrowsNotSupportedException()
{
var chunk = new ArrowResultChunk(_recordBatchOne);

Assert.Throws<NotSupportedException>(() => chunk.ExtractCell(0));
// Disable warning as we are testing the obsolete method behavior
#pragma warning disable CS0618 // Type or member is obsolete
Assert.Throws<NotSupportedException>(() => chunk.ExtractCell(0, 0));
#pragma warning restore CS0618 // Type or member is obsolete
}

[Test]
public void TestExtractCellReturnsNull()
{
Expand Down Expand Up @@ -192,7 +195,7 @@ public void TestExtractCellThrowsExceptionForNoneType()
{
var chunk = new ArrowResultChunk(_recordBatchOne);
chunk.Next();

Assert.Throws<NotSupportedException>(() => chunk.ExtractCell(0, SFDataType.None, 0));
}

Expand All @@ -201,7 +204,7 @@ public void TestExtractCellReturnsDecimal()
{
var testValues = new decimal[] { 0, 100, -100, Decimal.MaxValue, Decimal.MinValue };
var sfType = SFDataType.FIXED;

for (var scale = 0; scale <= 9; ++scale)
{
TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale));
Expand All @@ -219,7 +222,7 @@ public void TestExtractCellReturnsNumber64()
TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale));
}
}

[Test]
public void TestExtractCellReturnsNumber32()
{
Expand All @@ -229,9 +232,9 @@ public void TestExtractCellReturnsNumber32()
for (var scale = 0; scale <= 9; ++scale)
{
TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale));
}
}
}

[Test]
public void TestExtractCellReturnsNumber16()
{
Expand All @@ -243,7 +246,7 @@ public void TestExtractCellReturnsNumber16()
TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale));
}
}

[Test]
public void TestExtractCellReturnsNumber8()
{
Expand All @@ -255,7 +258,7 @@ public void TestExtractCellReturnsNumber8()
TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale));
}
}

[Test]
public void TestExtractCellReturnsBoolean()
{
Expand All @@ -265,7 +268,7 @@ public void TestExtractCellReturnsBoolean()

TestExtractCell(testValues, sfType, scale);
}

[Test]
public void TestExtractCellReturnsReal()
{
Expand All @@ -275,7 +278,7 @@ public void TestExtractCellReturnsReal()

TestExtractCell(testValues, sfType, scale);
}

[Test]
public void TestExtractCellReturnsText()
{
Expand All @@ -289,7 +292,7 @@ public void TestExtractCellReturnsText()

TestExtractCell(testValues, sfType, scale);
}

[Test]
public void TestExtractCellReturnsArray()
{
Expand Down Expand Up @@ -332,7 +335,7 @@ public void TestExtractCellReturnsDate()

TestExtractCell(testValues, sfType, scale);
}

[Test]
public void TestExtractCellReturnsTime()
{
Expand All @@ -343,14 +346,14 @@ public void TestExtractCellReturnsTime()
DateTime.Parse("9999-12-31 23:59:59.9999999")
};
var sfType = SFDataType.TIME;

for (var scale = 0; scale <= 8; ++scale)
{
var values = TruncateValues(testValues, scale);
TestExtractCell(values, sfType, scale);
}
}
}

[Test]
public void TestExtractCellReturnsTimestampTz()
{
Expand All @@ -364,14 +367,14 @@ public void TestExtractCellReturnsTimestampTz()
DateTimeOffset.Parse("9999-12-31 23:59:59.9999999 +0000"),
};
var sfType = SFDataType.TIMESTAMP_TZ;

for (var scale = 0; scale <= 9; ++scale)
{
var values = TruncateValues(testValues, scale);
TestExtractCell(values, sfType, scale);
}
}

[Test]
public void TestExtractCellReturnsTimestampLtz()
{
Expand All @@ -389,7 +392,7 @@ public void TestExtractCellReturnsTimestampLtz()
TestExtractCell(values, sfType, scale);
}
}

[Test]
public void TestExtractCellReturnsTimestampNtz()
{
Expand All @@ -400,14 +403,14 @@ public void TestExtractCellReturnsTimestampNtz()
DateTime.Parse("9999-12-31 23:59:59.9999999")
};
var sfType = SFDataType.TIMESTAMP_NTZ;

for (var scale = 0; scale <= 9; ++scale)
{
var values = TruncateValues(testValues, scale);
TestExtractCell(values, sfType, scale);
}
}

void TestExtractCell(IEnumerable testValues, SFDataType sfType, long scale, long divider = 0)
{
var recordBatch = PrepareRecordBatch(sfType, scale, testValues);
Expand All @@ -429,15 +432,15 @@ public static RecordBatch PrepareRecordBatch(SFDataType sfType, long scale, obje
case SFDataType.FIXED:
switch (values)
{
case decimal[] val:
case decimal[] val:
column = new Decimal128Array.Builder(new Decimal128Type(100, (int)scale))
.AppendRange(val.Select(v => v / (decimal)Math.Pow(10, scale)))
.Build();
break;
case long[] val:
case long[] val:
column = new Int64Array.Builder().AppendRange(val).Build();
break;
case int[] val:
case int[] val:
column = new Int32Array.Builder().AppendRange(val).Build();
break;
case short[] val:
Expand Down Expand Up @@ -481,7 +484,7 @@ public static RecordBatch PrepareRecordBatch(SFDataType sfType, long scale, obje
}
break;

case SFDataType.BINARY:
case SFDataType.BINARY:
column = new BinaryArray.Builder()
.AppendRange(values as byte[][])
.Build();
Expand Down Expand Up @@ -615,7 +618,7 @@ public static RecordBatch PrepareRecordBatch(SFDataType sfType, long scale, obje
.Append("TestColumn", false, column)
.Build();
}

private static long ConvertTicksToInt64(long ticks, long scale)
{
long ticksFromEpoch = ticks - SFDataConverter.UnixEpoch.Ticks;
Expand All @@ -624,7 +627,7 @@ private static long ConvertTicksToInt64(long ticks, long scale)
else
return ticksFromEpoch * (long)Math.Pow(10, scale - 7);
}

public static DateTime[] TruncateValues(DateTime[] testValues, int scale)
{
DateTime[] ret = new DateTime[testValues.Length];
Expand Down
4 changes: 2 additions & 2 deletions Snowflake.Data.Tests/UnitTests/SFAzureClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class SFAzureClientTest : SFBaseTest
SFFileMetadata _fileMetadata;

[SetUp]
public void BeforeTest()
public new void BeforeTest()
{
t_downloadFileName = TestNameWithWorker + "_mockFileName.txt";

_fileMetadata = new SFFileMetadata()
{
stageInfo = new PutGetStageInfo()
Expand Down
4 changes: 2 additions & 2 deletions Snowflake.Data.Tests/UnitTests/SFGCSClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class SFGCSClientTest : SFBaseTest
SFFileMetadata _fileMetadata;

[SetUp]
public void BeforeTest()
public new void BeforeTest()
{
t_downloadFileName = TestNameWithWorker + "_mockFileName.txt";

_fileMetadata = new SFFileMetadata()
{
stageInfo = new PutGetStageInfo()
Expand Down
Loading

0 comments on commit 1655d9e

Please sign in to comment.