private WorkAttempt doWork() {
        AgentIdentifier agentIdentifier = agentIdentifier();
        LOG.debug("[Agent Loop] {} is checking for work from Go", agentIdentifier);
        try {
            getAgentRuntimeInfo().idle();
            Work work = client.getWork(getAgentRuntimeInfo());
            LOG.debug("[Agent Loop] Got work from server: [{}]", work.description());
            runner = new JobRunner();
            final AgentWorkContext agentWorkContext = new AgentWorkContext(agentIdentifier, client, manipulator, getAgentRuntimeInfo(), packageRepositoryExtension, scmExtension, taskExtension, artifactExtension, pluginRequestProcessorRegistry);
            runner.run(work, agentWorkContext);
            LOG.debug("[Agent Loop] Successfully executed work.");
            return WorkAttempt.fromWork(work);
        } catch (UnregisteredAgentException e) {
            LOG.warn("[Agent Loop] Agent is not registered. [{}] Registering with server on next iteration.", e.getMessage());
            sslInfrastructureService.createSslInfrastructure();
            return WorkAttempt.FAILED;
        } finally {
            getAgentRuntimeInfo().idle();
        }
    }
@Test
    void shouldRetrieveCookieIfNotPresent() {
        agentController = createAgentController();
        agentController.init();

        when(loopServer.getCookie(eq(agentController.getAgentRuntimeInfo()))).thenReturn("cookie");
        when(sslInfrastructureService.isRegistered()).thenReturn(true);
        when(loopServer.getWork(agentController.getAgentRuntimeInfo())).thenReturn(work);
        when(agentRegistry.uuid()).thenReturn(agentUuid);
        when(pluginJarLocationMonitor.hasRunAtLeastOnce()).thenReturn(true);
        assertThat(agentController.performWork()).isEqualTo(WorkAttempt.OK);
        verify(work).doWork(any(), any());
    }