StoreKit test unable to test plan change scenario in iOS 17

I have a unit test case to test subscription plan change scenario, that is working until iOS 16, but the test failed starting iOS 17 and above.

Test case setup:

    let session = try SKTestSession(configurationFileNamed: "IAPTestConfiguration")
    session.disableDialogs = true
    session.clearTransactions()
   
    // Buy a monthly subscription first 
    try session.buyProduct(productIdentifier: "test.apple.test_mobile.1m")
    
    if let transaction = session.allTransactions().first {
        let id = transaction.identifier
        // and disable monthly subscription
        try session.disableAutoRenewForTransaction(identifier: id)
    }
    // buy a yearly subscription to create a subscription change scenario.
    try session.buyProduct(productIdentifier: "test.apple.test_mobile.1y")`

Now this is the logic I have to determine that there is going to be a plan change:

if let autoRenewPreference = renewalInfo.autoRenewPreference, autoRenewPreference != renewalInfo.currentProductID, renewalInfo.willAutoRenew {
   // means subscription change
}

until iOS 16, the above test setup resulted in :

renewalInfo.autoRenewPreference = "test.apple.test_mobile.1y"
renewalInfo.currentProductID = "test.apple.test_mobile.1m"
renewalInfo.willAutoRenew = true

But in iOS 17, the above setup seems to be not working because, the second time I try to buy a product seems to have no effect.

// This has no effect, when there is already an active subscription, in our case "test.apple.test_mobile.1m" .
try session.buyProduct(productIdentifier: "test.apple.test_mobile.1y")

I expect there should be at least two transactions with my current setup, in iOS 16 I get 2 transactions when I query session.allTransactions() at the end, but in iOS 17 I only get 1 transaction, which is the first buyProduct, the last buyProduct seems to have no effect, as I do not get any callback in the SKPaymentQueue updateTransactions method for the last buyProduct call. In iOS 16, I get callbacks in SKPaymnetQueue for both buyProduct calls.

I also tried to use async buyProduct in iOS 17, and updated my test case accordingly, but it resulted in the same behaviour.

Please let me know if you need any other detail that could help sort this issue.

StoreKit test unable to test plan change scenario in iOS 17
 
 
Q