private void bug40333Simulation(final Region region, final String queryStr) throws Exception {
    final QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion(SEPARATOR + "new_pos");
    for (int i = 1; i < 100; ++i) {
      NewPortfolio pf = new NewPortfolio("name" + i, i);
      rgn.put("name" + i, pf);
    }
    final Object lock = new Object();
    final boolean[] expectionOccurred = new boolean[] {false};
    final boolean[] keepGoing = new boolean[] {true};

    Thread indexCreatorDestroyer = new Thread(() -> {
      boolean continueRunning = true;
      do {
        synchronized (lock) {
          continueRunning = keepGoing[0];
        }
        try {
          Index indx1 = qs.createIndex("MarketValues", IndexType.FUNCTIONAL, "itr2.mktValue",
              SEPARATOR + "new_pos itr1, itr1.positions.values itr2");
          Index indx2 =
              qs.createIndex("Name", IndexType.FUNCTIONAL, "itr1.name",
                  SEPARATOR + "new_pos itr1");
          Index indx3 =
              qs.createIndex("nameIndex", IndexType.PRIMARY_KEY, "name", SEPARATOR + "new_pos");
          Index indx4 =
              qs.createIndex("idIndex", IndexType.FUNCTIONAL, "id", SEPARATOR + "new_pos");
          Index indx5 = qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status",
              SEPARATOR + "new_pos");
          Index indx6 = qs.createIndex("undefinedFieldIndex", IndexType.FUNCTIONAL,
              "undefinedTestField.toString", SEPARATOR + "new_pos");
          Thread.sleep(800);
          qs.removeIndex(indx1);
          qs.removeIndex(indx2);
          qs.removeIndex(indx3);
          qs.removeIndex(indx4);
          qs.removeIndex(indx5);
          qs.removeIndex(indx6);
        } catch (Throwable e) {
          region.getCache().getLogger().error(e);
          e.printStackTrace();
          synchronized (lock) {
            expectionOccurred[0] = true;
            keepGoing[0] = false;
            continueRunning = false;
          }

        }
      } while (continueRunning);
    });

    indexCreatorDestroyer.start();
    final Query q = qs.newQuery(queryStr);
    final int THREAD_COUNT = 10;
    Thread[] queryThreads = new Thread[THREAD_COUNT];
    final int numTimesToRun = 75;
    for (int i = 0; i < THREAD_COUNT; ++i) {
      queryThreads[i] = new Thread(() -> {
        boolean continueRunning = true;
        for (int i1 = 0; i1 < numTimesToRun && continueRunning; ++i1) {
          synchronized (lock) {
            continueRunning = keepGoing[0];
          }
          try {
            SelectResults sr = (SelectResults) q.execute();
          } catch (Throwable e) {
            e.printStackTrace();
            region.getCache().getLogger().error(e);
            synchronized (lock) {
              expectionOccurred[0] = true;
              keepGoing[0] = false;
              continueRunning = false;
            }
            break;
          }
        }
      });
    }
    synchronized (lock) {
      assertFalse(expectionOccurred[0]);
    }

    for (int i = 0; i < THREAD_COUNT; ++i) {
      queryThreads[i].start();
    }

    for (int i = 0; i < THREAD_COUNT; ++i) {
      queryThreads[i].join();
    }
    synchronized (lock) {
      keepGoing[0] = false;
    }

    indexCreatorDestroyer.join();
    synchronized (lock) {
      assertFalse(expectionOccurred[0]);
    }
  }
Commented the test as it is for some reason causing OOM when run in the suite. It is due to
presence of PR Tests the where clause formed with CompiledComparison nesting with CompiledIN
geode-core/src/integrationTest/java/org/apache/geode/cache/query/functional/MiscJUnitTest.java