Beispiel #1
0
   def test_generator_loop(self):
      genq = queue.Queue(10)
      senderq = queue.Queue(10)
      lqueue = queue.Queue(100)

      testgen = generator.taskGenerator(1, self.name, genq, senderq, lqueue, \
                                        'testcourse.db', 'testsemester.db', \
                                        "*****@*****.**")

      os.mkdir("users/42")
      genq.put(dict({"user_id": "42", "user_email": "*****@*****.**", \
                     "task_nr": "1", "messageid": "47110815"}))

      testgen.generator_loop()
      sendout = senderq.get(False, 1)
      self.assertEqual(sendout.get('recipient'), "*****@*****.**")
      self.assertEqual(sendout.get('message_type'), "Task")
      self.assertEqual(sendout.get('Task'), "1")

      genq.put(dict({"user_id": "42", "user_email": "*****@*****.**", \
                     "task_nr": "11", "messageid": "47110815"}))

      testgen.generator_loop()
      sendout = senderq.get(False, 1)

      self.assertEqual(sendout.get('recipient'), "*****@*****.**")
      self.assertEqual(sendout.get('message_type'), "Task")
      self.assertEqual(sendout.get('Task'), "11")

      os.removedirs("users/42/Task1/desc")
      os.removedirs("users/42/Task11/desc")
Beispiel #2
0
    def test_generator_loop(self):
        genq = queue.Queue(10)
        senderq = queue.Queue(10)
        lqueue = queue.Queue(100)

        testgen = generator.taskGenerator(1, self.name, genq, senderq, lqueue, \
                                          'testcourse.db', 'testsemester.db', \
                                          "*****@*****.**")

        os.mkdir("users/42")
        genq.put(dict({"user_id": "42", "user_email": "*****@*****.**", \
                       "task_nr": "1", "messageid": "47110815"}))

        testgen.generator_loop()
        sendout = senderq.get(False, 1)
        self.assertEqual(sendout.get('recipient'), "*****@*****.**")
        self.assertEqual(sendout.get('message_type'), "Task")
        self.assertEqual(sendout.get('Task'), "1")

        genq.put(dict({"user_id": "42", "user_email": "*****@*****.**", \
                       "task_nr": "11", "messageid": "47110815"}))

        testgen.generator_loop()
        sendout = senderq.get(False, 1)

        self.assertEqual(sendout.get('recipient'), "*****@*****.**")
        self.assertEqual(sendout.get('message_type'), "Task")
        self.assertEqual(sendout.get('Task'), "11")

        os.removedirs("users/42/Task1/desc")
        os.removedirs("users/42/Task11/desc")
Beispiel #3
0
    def test_load_code(self):
        threadID = 2  # LOGGER IS NUMBER 1 !!!
        queueSize = 500
        poll_period = 5
        numThreads = 8
        worker_t = []

        job_queue = queue.Queue(queueSize)
        sender_queue = queue.Queue(queueSize)
        gen_queue = queue.Queue(queueSize)
        arch_queue = queue.Queue(queueSize)

        self.email_queue = queue.Queue(20000) # used by the mock-up sender function instead of smtp

        self.clean_whitelist()
        self.clean_users()
        self.clean_usertasks()
        self.clean_statcounters()
        self.clean_taskstats()
        self.clean_generalconfig()
        self.clean_specialmsg()
        self.clean_taskconfig()

        curc, conc = c.connect_to_db(self.coursedb, self.logger_queue, "loadtester")

        this_time_yesterday = str(datetime.datetime.now() - datetime.timedelta(1)).split('.')[0]
        this_time_tomorrow = str(datetime.datetime.now() + datetime.timedelta(1)).split('.')[0]

        self.add_task(curc, conc, 1, this_time_yesterday, this_time_tomorrow, \
                      'tasks/implementation/VHDL/gates', 'generator.sh', \
                      'tester.sh', '5', '[email protected]', '1')
        self.add_task(curc, conc, 2, this_time_yesterday, this_time_tomorrow, \
                      'tasks/implementation/VHDL/fsm', 'generator.sh', \
                      'tester.sh', '5', '[email protected]', '1')

        conc.close()

        for i in range(1, self.numusers+1):
            self.insert_email_to_whitelist("testuser{0}@sometestdomain.abc".format(str(i)))
     
        with mock.patch.multiple('fetcher.mailFetcher',
                                 connect_to_imapserver=self.mock_connect_to_imapserver,
                                 fetch_new_emails=self.mock_fetch_new_emails,
                                 fetch_all_emails=self.mock_fetch_all_emails):
            with mock.patch.multiple("imaplib.IMAP4",
                                     fetch=self.mock_fetch,
                                     close=self.mock_close):
                with mock.patch("sender.MailSender.send_out_email", self.mock_send_out_email):

                    while threadID <= numThreads + 1:
                        tName = "Worker" + str(threadID-1)
                        t = worker.Worker(tName, job_queue, gen_queue, \
                                          sender_queue, self.logger_queue, \
                                          self.coursedb, self.semesterdb)
                        t.daemon = True
                        t.start()
                        worker_t.append(t)
                        threadID += 1

                    sender_t = sender.MailSender("sender", \
                                                 sender_queue, \
                                                 "[email protected]", \
                                                 "autosub_user", \
                                                 "autosub_passwd", \
                                                 "smtpserver", \
                                                 self.logger_queue, \
                                                 arch_queue, \
                                                 self.coursedb, \
                                                 self.semesterdb)
                    sender_t.daemon = True 
                    sender_t.start()
                    threadID += 1

                    fetcher_t = fetcher.mailFetcher(threadID, "fetcher", \
                                                    job_queue, sender_queue, \
                                                    gen_queue, "autosub_user", \
                                                    "autosub_passwd", \
                                                    "imapserver", \
                                                    self.logger_queue, \
                                                    arch_queue, poll_period, \
                                                    self.coursedb, \
                                                    self.semesterdb)
                    fetcher_t.daemon = True
                    fetcher_t.start()
                    threadID += 1

                    generator_t = generator.taskGenerator(threadID, \
                                                          "generator", \
                                                          gen_queue, \
                                                          sender_queue, \
                                                          self.logger_queue, \
                                                          self.coursedb, \
                                                          self.semesterdb, \
                                                          "*****@*****.**")
                    generator_t.daemon = True
                    generator_t.start()
                    threadID += 1

                    t1 = datetime.datetime.now()
                    # There first test case is set above in the setup routine: self.testcase = "b'10'"
                    NrEntries = 0
                    while NrEntries < self.numusers:
                        curs, cons = c.connect_to_db(self.semesterdb, \
                                                     self.logger_queue, "testcode")
                        sqlcmd = "SELECT count(*) FROM UserTasks;"
                        curs.execute(sqlcmd)
                        NrEntries = int(curs.fetchone()[0])
                        cons.close()
                        #print(NrEntries)

                    t2 = datetime.datetime.now()

                    tc = "b'84'"
                    config = CP.ConfigParser()
                    config.readfp(open('tests/loadtest_testcases.cfg'))
                    testparam = eval(str(config.get(tc, 'generatorstring')))

                    curs, cons = c.connect_to_db(self.semesterdb, \
                                                 self.logger_queue, "testcode")
                    sqlcmd = ("UPDATE UserTasks SET "
                              "TaskParameters = '162159553761823' "
                              "WHERE TaskNr==1;").format(testparam)
                    curs.execute(sqlcmd)
                    cons.commit()
                    cons.close()

                    self.testcase = tc

                    while NrEntries < self.numusers:
                        curs, cons = c.connect_to_db(self.semesterdb, self.logger_queue, "testcode")
                        sqlcmd = "SELECT count(*) FROM UserTasks;"
                        curs.execute(sqlcmd)
                        NrEntries = int(curs.fetchone()[0])
                        cons.close() 

                    t3 = datetime.datetime.now()
                    delta1 = t2 - t1
                    delta2 = t3 - t2
                    print ("Duration of Registration Test: {0} s {1} us".format(delta1.seconds, delta1.microseconds))
                    print ("Duration of Result Test: {0} s {1} us".format(delta2.seconds, delta2.microseconds))
Beispiel #4
0
    sender_t.start()
    thread_id += 1

    fetcher_t = fetcher.mailFetcher(thread_id, "fetcher", job_queue, sender_queue, gen_queue, \
                                    imapuser, imappasswd, imapserver, imapport, imapsecurity, \
                                    logger_queue, arch_queue, poll_period, coursedb, \
                                    semesterdb, allow_skipping)

    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!
    fetcher_t.daemon = True
    fetcher_t.start()
    thread_id += 1

    generator_t = generator.taskGenerator(thread_id, "generator", gen_queue, \
                                          sender_queue, logger_queue, coursedb, \
                                          semesterdb, imapmail)

    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!
    generator_t.daemon = True
    generator_t.start()
    thread_id += 1

    activator_t = activator.TaskActivator("activator", gen_queue, \
                                          sender_queue, logger_queue, coursedb, \
                                          semesterdb, auto_advance)

    # make the fetcher thread a daemon, this way the main will clean it up before
    # terminating!
    activator_t.daemon = True