Skip to content

Commit 3cffa21

Browse files
authored
SyncTriggers hash blob update fix (#7469)
1 parent 15cf9b7 commit 3cffa21

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ internal async Task UpdateHashAsync(BlobClient hashBlobClient, string hash)
247247
// update the last hash value in storage
248248
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(hash)))
249249
{
250-
await hashBlobClient.UploadAsync(stream);
250+
await hashBlobClient.UploadAsync(stream, overwrite: true);
251251
}
252252
_logger.LogDebug($"SyncTriggers hash updated to '{hash}'");
253253
}

test/WebJobs.Script.Tests.Integration/Management/FunctionsSyncManagerTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,35 @@ public async Task TrySyncTriggers_DurableV2ExtensionJson_V2ConfigPosted()
568568
}
569569
}
570570

571+
[Fact]
572+
public async Task UpdateHashAsync_Succeeds()
573+
{
574+
var hashBlobClient = await _functionsSyncManager.GetHashBlobAsync();
575+
await hashBlobClient.DeleteIfExistsAsync();
576+
577+
// add the hash when it doesn't exist
578+
await _functionsSyncManager.UpdateHashAsync(hashBlobClient, "hash1");
579+
580+
// read the hash and make sure the value is what we wrote
581+
string result;
582+
var downloadResponse = await hashBlobClient.DownloadAsync();
583+
using (StreamReader reader = new StreamReader(downloadResponse.Value.Content))
584+
{
585+
result = reader.ReadToEnd();
586+
}
587+
Assert.Equal("hash1", result);
588+
589+
// now update the existing hash to a new value
590+
await _functionsSyncManager.UpdateHashAsync(hashBlobClient, "hash2");
591+
592+
downloadResponse = await hashBlobClient.DownloadAsync();
593+
using (StreamReader reader = new StreamReader(downloadResponse.Value.Content))
594+
{
595+
result = reader.ReadToEnd();
596+
}
597+
Assert.Equal("hash2", result);
598+
}
599+
571600
private void VerifyLoggedInvalidOperationException(string errorMessage)
572601
{
573602
Exception[] messages = _loggerProvider.GetAllLogMessages().Where(m => m.Category.Equals(SyncManagerLogCategory)).Where(p => p.Level == LogLevel.Error).Select(p => p.Exception).ToArray();

0 commit comments

Comments
 (0)