okta / okta-sdk-golang

A Golang SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
https://github.com/okta/okta-sdk-golang
Other
180 stars 145 forks source link

Error when running Integration tests on client.Group.ListGroupUsers #293

Open pputman12 opened 2 years ago

pputman12 commented 2 years ago

Describe the bug?

This is hard to describe and its very confusing. I have two integration tests I'm writing for Terraform with Okta. The bug happens with this code:

image

This code is my workaround, to keep retrying to run client.Group.ListGroupUsers if it returns an empty slice. This is part one okta test I have that verifies a group has the necessary users. If I run this test separately, it works fine. I then created a new test in a different go file, that has this code, and if I run go test on the entire directory, I will have a problem with the above method (ListGroupUsers) returning an empty slice, until I keep retrying and it finally returns the Users slice.

In my second test I've narrowed it down to this method:

image

So if I run this second test, with ListAssignedApplicationsForGroup by running go test on the directory, the ListGroupUsers returns null until my work around has it kee retrying (for like 2 minutes it takes) to get it. Kinda weird.

image

Here's my workaround priting the array and length until it isn't empty for testing (and sleeping 10 seconds between)

image

So once again I'm not sure how having another integration test calling a completey different method is somehow breaking the api call in the first integration test. So confused I didn't even really want to write this up as I don't even know how to properly articulate/prove it.

What is expected to happen?

Test should run and pass,

What is the actual behavior?

If one test exists, its fine, however introducing a second test that calls a separate method somehow causes the first test to fail because of an empty slice, unless I implement a workaround that keeps trying

Reproduction Steps?

Maybe see if there's an issue with calling multiple methods listed Group.ListAssignedApplicationsForGroup(ctx, appId, nil) and then Group.ListGroupUsers(ctx, groupId, nil) to see if there's an issue?

Additional Information?

I checked okta's rate limit and didn't see anything in the logs. No errors, just an empty slice returning only in this one condition.

Golang Version

1.18 and 1.18.1

SDK Version

latest

OS version

No response

monde commented 2 years ago

@pputman12 try setting up your okta client with query caching disabled and tell me what you find:

  ctx, client, err := okta.NewClient(
    context.TODO(),
    okta.WithCache(false),
    okta.WithOrgUrl("https://{yourOktaDomain}"),
    okta.WithToken("{apiToken}"),
  )
monde commented 2 years ago

fwiw, here is the ListAssignedApplications integration test I added after the #292 discussion https://github.com/okta/okta-sdk-golang/pull/294

pputman12 commented 2 years ago

setting up false with caching worked, thank you so much, I was genuinely confused.

monde commented 2 years ago

setting up false with caching worked, thank you so much, I was genuinely confused.

Same for me. Our Okta Terraform Provider runs okta-sdk-golang w/o query caching so I get used to that and forgot about the query caching fighting that PR I referenced.

pputman12 commented 2 years ago

Yeah, I'm writing unit and integration tests for some okta modules I made with terratest golang library. But this was a big help, I really appreciate your quick response.

On Thu, Apr 21, 2022 at 10:11 AM Mike Mondragon @.***> wrote:

setting up false with caching worked, thank you so much, I was genuinely confused.

Same for me. Our Okta Terraform Provider https://github.com/okta/terraform-provider-okta runs okta-sdk-golang w/o query caching so I get used to that and forgot about the query caching fighting that PR I referenced.

— Reply to this email directly, view it on GitHub https://github.com/okta/okta-sdk-golang/issues/293#issuecomment-1105356683, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNEWVYYKMT5ZKTSGFTRPLVGFVZVANCNFSM5T455L4A . You are receiving this because you were mentioned.Message ID: @.***>

pputman12 commented 2 years ago

So I tested this a few more times, and sometimes it works, other times it fails with the same issue, so it looks like setting the cache to false didn't resolve it. Is there anything else I can try?

On Thu, Apr 21, 2022 at 1:35 PM Patrick Putman @.***> wrote:

Yeah, I'm writing unit and integration tests for some okta modules I made with terratest golang library. But this was a big help, I really appreciate your quick response.

On Thu, Apr 21, 2022 at 10:11 AM Mike Mondragon @.***> wrote:

setting up false with caching worked, thank you so much, I was genuinely confused.

Same for me. Our Okta Terraform Provider https://github.com/okta/terraform-provider-okta runs okta-sdk-golang w/o query caching so I get used to that and forgot about the query caching fighting that PR I referenced.

— Reply to this email directly, view it on GitHub https://github.com/okta/okta-sdk-golang/issues/293#issuecomment-1105356683, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNEWVYYKMT5ZKTSGFTRPLVGFVZVANCNFSM5T455L4A . You are receiving this because you were mentioned.Message ID: @.***>

pputman12 commented 2 years ago

@monde can we reopen this? I'm still seeing the problem, its just intermittent.

monde commented 2 years ago

"While I thought this was fixed, its because its intermittent. testing several more times with query caching disabled, and still receiving the same issue."

github-actions[bot] commented 2 years ago

This issue has been marked stale because there has been no activity within the last 14 days. To keep this issue active, remove the stale label.