0

I am experiencing latency when doing queries against the Google Admin API.

def get_user(self, email: str) -> dict:
    res = (
        self.service.users()
        .list(
            domain="gmail.com",
            projection="full",
            query="email={0}".format(email),
        )
        .execute()
    )

    if "users" not in res or len(res["users"]) != 1:
        msg = "Could not find user %s" % email
        logging.error(msg)
        raise GoogleAdminNonExistentUser(msg)

    return res["users"][0]

def create_user(
    self,
    email: str,
    first_name: str,
    last_name: str,
    org_unit_path: str,
    manager_email: str,
) -> dict:
    user_info = {...}

    try:
        res = self.service.users().insert(body=user_info).execute()
        return res
    except HttpError as error:
        exc = self._generate_error(error)
        logger.exception(exc.message)
        raise exc

Take for example these two calls. In my test suite, I do a test for creating a user and immediately deleting them. In the next test I create the same user and update custom attributes. I then validate that those attributes were set.

test_create_delete()
    create_user(EMAIL)
    delete_user(EMAIL)

test_create_update()
    create_user(EMAIL) # This will variably error out if the delete_user from the last request hasn't replicated throughout Google
    update_user(EMAIL, UPDATE_INFO)
    user = get_user()
    # This assertion will variably fail if get_user() fetches old data
    assert the update info is in user

I could liter the tests with sleeps, but build time is important. Is there a way to force the Google Admin API to return the freshest data possible?

user1222324562
  • 965
  • 2
  • 9
  • 24
  • 1
    The simple answer is no. This is a global service that takes time to sync and this is measured in minutes, not microseconds. – John Hanley Jun 26 '19 at 08:50

1 Answers1

0

Not possible because it has many dependent services. We have on-going projects for improvement on the performance though. (I'm one of the developers behind these services, and just ran across this question.)

Fent
  • 1