@@ -84,7 +84,7 @@ public static class FunctionalTest
84
84
"IObservable<MinioNotificationRaw> ListenBucketNotificationsAsync(ListenBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))" ;
85
85
86
86
private const string listenNotificationsSignature =
87
- "IObservable<MinioNotificationRaw> ListenNotificationsAsync(IList<EventType> events , CancellationToken cancellationToken = default(CancellationToken))" ;
87
+ "IObservable<MinioNotificationRaw> ListenNotifications(ListenBucketNotificationsArgs args , CancellationToken cancellationToken = default(CancellationToken))" ;
88
88
89
89
private const string copyObjectSignature =
90
90
"Task<CopyObjectResult> CopyObjectAsync(CopyObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))" ;
@@ -1041,13 +1041,11 @@ internal static async Task<bool> CreateBucket_Tester(IMinioClient minio, string
1041
1041
{
1042
1042
// Create a new bucket
1043
1043
await minio . MakeBucketAsync ( new MakeBucketArgs ( ) . WithBucket ( bucketName ) ) . ConfigureAwait ( false ) ;
1044
+ await Task . Delay ( 800 ) . ConfigureAwait ( false ) ;
1044
1045
1045
1046
// Verify the bucket exists
1046
- var bucketExists = await minio . BucketExistsAsync ( new BucketExistsArgs ( ) . WithBucket ( bucketName ) )
1047
+ return await minio . BucketExistsAsync ( new BucketExistsArgs ( ) . WithBucket ( bucketName ) )
1047
1048
. ConfigureAwait ( false ) ;
1048
- Assert . IsTrue ( bucketExists , $ "Bucket { bucketName } was not created successfully.") ;
1049
-
1050
- return bucketExists ;
1051
1049
}
1052
1050
1053
1051
internal static async Task StatObject_Test1 ( IMinioClient minio )
@@ -1282,7 +1280,7 @@ internal static async Task RemoveObjects_Test3(IMinioClient minio)
1282
1280
. WithBucket ( bucketName )
1283
1281
. WithObjectsVersions ( objVersions ) ;
1284
1282
1285
- await minio . RemoveObjectsAsync ( removeObjectsArgs ) . ConfigureAwait ( false ) ;
1283
+ _ = await minio . RemoveObjectsAsync ( removeObjectsArgs ) . ConfigureAwait ( false ) ;
1286
1284
1287
1285
await TearDown ( minio , bucketName ) . ConfigureAwait ( false ) ;
1288
1286
@@ -2639,7 +2637,7 @@ await ListObjects_Test(minio, bucketName, singleObjectName, 1, headers: extractH
2639
2637
2640
2638
#region Global Notifications
2641
2639
2642
- internal static async Task ListenNotificationsAsync_Test1 ( IMinioClient minio )
2640
+ internal static async Task ListenNotifications_Test1 ( IMinioClient minio )
2643
2641
{
2644
2642
var startTime = DateTime . Now ;
2645
2643
var bucketName = GetRandomName ( 15 ) ;
@@ -2648,61 +2646,54 @@ internal static async Task ListenNotificationsAsync_Test1(IMinioClient minio)
2648
2646
try
2649
2647
{
2650
2648
var received = new List < MinioNotificationRaw > ( ) ;
2651
-
2652
2649
var eventsList = new List < EventType > { EventType . BucketCreatedAll } ;
2653
2650
2654
- var events = minio . ListenNotificationsAsync ( eventsList ) ;
2655
- var subscription = events . Subscribe (
2656
- received . Add ,
2657
- ex => Console . WriteLine ( $ "OnError: { ex } ") ,
2658
- ( ) => Console . WriteLine ( "Stopped listening for bucket notifications\n " ) ) ;
2659
-
2660
- // Ensure the subscription is established
2661
- await Task . Delay ( 1000 ) . ConfigureAwait ( false ) ;
2662
-
2663
- // Trigger the event by creating a new bucket
2664
- var isBucketCreated1 = await CreateBucket_Tester ( minio , bucketName ) . ConfigureAwait ( false ) ;
2665
-
2651
+ // No need to define a new "ListenNotificationArgs"
2652
+ // "ListenBucketNotificationsArgs" is good here
2653
+ var listenArgs = new ListenBucketNotificationsArgs ( )
2654
+ . WithEvents ( eventsList ) ;
2655
+ var events = minio . ListenNotifications ( listenArgs ) ;
2666
2656
var eventDetected = false ;
2657
+ using ( var subscription = events . Subscribe (
2658
+ received . Add ,
2659
+ _ => { } ,
2660
+ ( ) => { } ) )
2661
+ {
2662
+ await Task . Delay ( 200 ) . ConfigureAwait ( false ) ;
2663
+ // Trigger the event by creating a new bucket
2664
+ _ = await CreateBucket_Tester ( minio , bucketName ) . ConfigureAwait ( false ) ;
2665
+ }
2666
+
2667
2667
for ( var attempt = 0 ; attempt < 20 ; attempt ++ )
2668
- {
2669
- if ( received . Count > 0 )
2668
+ // Check if there is a caught event
2669
+ if ( received . Count == 1 )
2670
2670
{
2671
2671
var notification = JsonSerializer . Deserialize < MinioNotification > ( received [ 0 ] . Json ) ;
2672
2672
2673
2673
if ( notification . Records is not null )
2674
2674
{
2675
2675
Assert . AreEqual ( 1 , notification . Records . Count ) ;
2676
+ Assert . IsTrue ( notification . Records [ 0 ] . EventName
2677
+ . Contains ( "s3:BucketCreated:*" , StringComparison . OrdinalIgnoreCase ) ) ;
2676
2678
eventDetected = true ;
2677
2679
break ;
2678
2680
}
2679
2681
}
2680
2682
2681
- await Task . Delay ( 500 ) . ConfigureAwait ( false ) ; // Delay between attempts
2682
- }
2683
-
2684
- subscription . Dispose ( ) ;
2685
- if ( ! eventDetected )
2686
- throw new UnexpectedMinioException ( "Failed to detect the expected bucket notification event." ) ;
2687
-
2688
- new MintLogger ( nameof ( ListenNotificationsAsync_Test1 ) ,
2689
- listenNotificationsSignature ,
2690
- "Tests whether ListenNotifications passes" ,
2691
- TestStatus . PASS , DateTime . Now - startTime , args : args ) . Log ( ) ;
2692
- }
2693
- catch ( NotImplementedException ex )
2694
- {
2695
- new MintLogger ( nameof ( ListenNotificationsAsync_Test1 ) ,
2696
- listenNotificationsSignature ,
2697
- "Tests whether ListenNotifications passes" ,
2698
- TestStatus . NA , DateTime . Now - startTime , ex . Message ,
2699
- ex . ToString ( ) , args : args ) . Log ( ) ;
2683
+ if ( eventDetected )
2684
+ new MintLogger ( nameof ( ListenNotifications_Test1 ) ,
2685
+ listenNotificationsSignature ,
2686
+ "Tests whether ListenNotifications notifies user about \" BucketCreatedAll\" event" ,
2687
+ TestStatus . PASS , DateTime . Now - startTime , args : args ) . Log ( ) ;
2688
+ else
2689
+ throw new UnexpectedMinioException (
2690
+ "Failed to detect the expected notification event, \" BucketCreatedAll\" ." ) ;
2700
2691
}
2701
2692
catch ( Exception ex )
2702
2693
{
2703
- new MintLogger ( nameof ( ListenNotificationsAsync_Test1 ) ,
2694
+ new MintLogger ( nameof ( ListenNotifications_Test1 ) ,
2704
2695
listenNotificationsSignature ,
2705
- "Tests whether ListenNotifications passes " ,
2696
+ "Tests whether ListenNotifications notifies user about \" BucketCreatedAll \" event " ,
2706
2697
TestStatus . FAIL , DateTime . Now - startTime , ex . Message ,
2707
2698
ex . ToString ( ) , args : args ) . Log ( ) ;
2708
2699
throw ;
@@ -2738,57 +2729,26 @@ internal static async Task ListenBucketNotificationsAsync_Test1(IMinioClient min
2738
2729
var received = new List < MinioNotificationRaw > ( ) ;
2739
2730
2740
2731
var eventsList = new List < EventType > { EventType . ObjectCreatedAll } ;
2732
+ var eventDetected = false ;
2741
2733
2742
2734
var listenArgs = new ListenBucketNotificationsArgs ( )
2743
2735
. WithBucket ( bucketName )
2744
2736
. WithEvents ( eventsList ) ;
2745
2737
var events = minio . ListenBucketNotificationsAsync ( listenArgs ) ;
2746
- var subscription = events . Subscribe (
2747
- received . Add ,
2748
- ex => { } ,
2749
- ( ) => { }
2750
- ) ;
2751
-
2752
-
2753
- _ = await PutObject_Tester ( minio , bucketName , objectName , null , contentType ,
2754
- 0 , null , rsg . GenerateStreamFromSeed ( 1 * KB ) ) . ConfigureAwait ( false ) ;
2738
+ using ( var subscription = events . Subscribe (
2739
+ received . Add ,
2740
+ _ => { } ,
2741
+ ( ) => { } ) )
2742
+ {
2743
+ _ = await PutObject_Tester ( minio , bucketName , objectName , null , contentType ,
2744
+ 0 , null , rsg . GenerateStreamFromSeed ( 1 * KB ) ) . ConfigureAwait ( false ) ;
2745
+ }
2755
2746
2756
- // wait for notifications
2757
- var eventDetected = false ;
2758
- for ( var attempt = 0 ; attempt < 10 ; attempt ++ )
2759
- if ( received . Count > 0 )
2747
+ for ( var attempt = 0 ; attempt < 20 ; attempt ++ )
2748
+ // Check if there is a caught event
2749
+ if ( received . Count == 1 )
2760
2750
{
2761
- // Check if there is any unexpected error returned
2762
- // and captured in the receivedJson list, like
2763
- // "NotImplemented" api error. If so, we throw an exception
2764
- // and skip running this test
2765
- if ( received . Count > 1 &&
2766
- received [ 1 ] . Json . StartsWith ( "<Error><Code>" , StringComparison . OrdinalIgnoreCase ) )
2767
- {
2768
- // Although the attribute is called "json",
2769
- // returned data in list "received" is in xml
2770
- // format and it is an error.Here, we convert xml
2771
- // into json format.
2772
- var receivedJson = XmlStrToJsonStr ( received [ 1 ] . Json ) ;
2773
-
2774
- // Cleanup the "Error" key encapsulating "receivedJson"
2775
- // data. This is required to match and convert json data
2776
- // "receivedJson" into class "ErrorResponse"
2777
- var len = "{'Error':" . Length ;
2778
- var trimmedFront = receivedJson [ len ..] ;
2779
- var trimmedFull = trimmedFront [ ..^ 1 ] ;
2780
-
2781
- var err = JsonSerializer . Deserialize < ErrorResponse > ( trimmedFull ) ;
2782
-
2783
- Exception ex = new UnexpectedMinioException ( err . Message ) ;
2784
- if ( string . Equals ( err . Code , "NotImplemented" , StringComparison . OrdinalIgnoreCase ) )
2785
- ex = new NotImplementedException ( err . Message ) ;
2786
- await TearDown ( minio , bucketName ) . ConfigureAwait ( false ) ;
2787
- throw ex ;
2788
- }
2789
-
2790
2751
var notification = JsonSerializer . Deserialize < MinioNotification > ( received [ 0 ] . Json ) ;
2791
-
2792
2752
if ( notification . Records is not null )
2793
2753
{
2794
2754
Assert . AreEqual ( 1 , notification . Records . Count ) ;
@@ -2804,20 +2764,19 @@ internal static async Task ListenBucketNotificationsAsync_Test1(IMinioClient min
2804
2764
}
2805
2765
}
2806
2766
2807
- // subscription.Dispose();
2808
- if ( ! eventDetected )
2767
+ if ( eventDetected )
2768
+ new MintLogger ( nameof ( ListenBucketNotificationsAsync_Test1 ) ,
2769
+ listenBucketNotificationsSignature ,
2770
+ "Tests whether ListenBucketNotifications passes for small object" ,
2771
+ TestStatus . PASS , DateTime . Now - startTime , args : args ) . Log ( ) ;
2772
+ else
2809
2773
throw new UnexpectedMinioException ( "Failed to detect the expected bucket notification event." ) ;
2810
-
2811
- new MintLogger ( nameof ( ListenBucketNotificationsAsync_Test1 ) ,
2812
- listenBucketNotificationsSignature ,
2813
- "Tests whether ListenBucketNotifications passes for small object" ,
2814
- TestStatus . PASS , DateTime . Now - startTime , args : args ) . Log ( ) ;
2815
2774
}
2816
2775
catch ( NotImplementedException ex )
2817
2776
{
2818
2777
new MintLogger ( nameof ( ListenBucketNotificationsAsync_Test1 ) ,
2819
2778
listenBucketNotificationsSignature ,
2820
- "Tests whether ListenBucketNotifications passes for small object" ,
2779
+ "Tests whether ListenBucketNotifications generates notification for a newly created object. " ,
2821
2780
TestStatus . NA , DateTime . Now - startTime , ex . Message ,
2822
2781
ex . ToString ( ) , args : args ) . Log ( ) ;
2823
2782
}
@@ -2841,14 +2800,14 @@ static bool isAWS(string endPoint)
2841
2800
// This is a PASS
2842
2801
new MintLogger ( nameof ( ListenBucketNotificationsAsync_Test1 ) ,
2843
2802
listenBucketNotificationsSignature ,
2844
- "Tests whether ListenBucketNotifications passes for small object" ,
2803
+ "Tests whether ListenBucketNotifications generates notification for a newly created object. " ,
2845
2804
TestStatus . PASS , DateTime . Now - startTime , args : args ) . Log ( ) ;
2846
2805
}
2847
2806
else
2848
2807
{
2849
2808
new MintLogger ( nameof ( ListenBucketNotificationsAsync_Test1 ) ,
2850
2809
listenBucketNotificationsSignature ,
2851
- "Tests whether ListenBucketNotifications passes for small object" ,
2810
+ "Tests whether ListenBucketNotifications generates notification for a newly created object. " ,
2852
2811
TestStatus . FAIL , DateTime . Now - startTime , ex . Message ,
2853
2812
ex . ToString ( ) , args : args ) . Log ( ) ;
2854
2813
throw ;
0 commit comments