[TEST] Force LDAP connection to close at end of test (elastic/x-pack-elasticsearch#1620)
This test would sometime leak threads. The "Timer thread for LDAPConnection" is created by the unboundid SDK - closing the connection should force the thread to terminate Original commit: elastic/x-pack-elasticsearch@bd58a17a59
This commit is contained in:
parent
376c9be6fa
commit
a12b384906
|
@ -13,37 +13,39 @@ import com.unboundid.ldap.sdk.LDAPConnectionOptions;
|
|||
import com.unboundid.ldap.sdk.LDAPException;
|
||||
import com.unboundid.ldap.sdk.LDAPURL;
|
||||
import com.unboundid.ldap.sdk.ResultCode;
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.action.support.PlainActionFuture;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapSearchScope;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapTestCase;
|
||||
import org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils;
|
||||
import org.junit.After;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/x-pack-elasticsearch/issues/971")
|
||||
public class SearchGroupsResolverInMemoryTests extends LdapTestCase {
|
||||
|
||||
private LDAPConnection connection;
|
||||
|
||||
@After
|
||||
public void closeConnection() {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a client-side timeout in the asynchronous LDAP SDK is treated as a failure, rather
|
||||
* than simply returning no results.
|
||||
*/
|
||||
public void testSearchTimeoutIsFailure() throws Exception {
|
||||
|
||||
ldapServers[0].setProcessingDelayMillis(100);
|
||||
|
||||
final LDAPConnectionOptions options = new LDAPConnectionOptions();
|
||||
options.setConnectTimeoutMillis(500);
|
||||
options.setResponseTimeoutMillis(5);
|
||||
|
||||
final LDAPURL ldapurl = new LDAPURL(ldapUrls()[0]);
|
||||
final LDAPConnection connection = LdapUtils.privilegedConnect(
|
||||
() -> new LDAPConnection(options,
|
||||
ldapurl.getHost(), ldapurl.getPort())
|
||||
);
|
||||
connect(options);
|
||||
|
||||
final Settings settings = Settings.builder()
|
||||
.put("group_search.base_dn", "ou=groups,o=sevenSeas")
|
||||
|
@ -63,4 +65,13 @@ public class SearchGroupsResolverInMemoryTests extends LdapTestCase {
|
|||
assertThat(((LDAPException) cause).getResultCode(), is(ResultCode.TIMEOUT));
|
||||
}
|
||||
|
||||
private void connect(LDAPConnectionOptions options) throws LDAPException {
|
||||
if (connection != null) {
|
||||
throw new IllegalStateException("Already connected (" + connection.getConnectionName() + ' '
|
||||
+ connection.getConnectedAddress() + ')');
|
||||
}
|
||||
final LDAPURL ldapurl = new LDAPURL(ldapUrls()[0]);
|
||||
this.connection = LdapUtils.privilegedConnect(() -> new LDAPConnection(options, ldapurl.getHost(), ldapurl.getPort()));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue