From f46463cc53fd084248357c737ee00af084390573 Mon Sep 17 00:00:00 2001 From: Bradiowave Date: Wed, 15 Aug 2018 16:05:27 -0700 Subject: [PATCH] 6/17 Queue.test.js failing --- src/Queue.js | 38 +++++++++++++++++++++++++++++--------- yarn-error.log | 4 ++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Queue.js b/src/Queue.js index 7b45fdf..f7ce710 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -19,29 +19,31 @@ class Queue { // Enqueues the given process. Return the enqueue'd process enqueue(process) { - + this.processes.push(process); + process.setParentQueue(this); + return process; } // Dequeues the next process in the queue. Return the dequeue'd process dequeue() { - + return this.processes.shift(); } // Return the least-recently added process without removing it from the list of processes peek() { - + return this.processes[0]; } isEmpty() { - + return (this.processes == 0); } getPriorityLevel() { - + return this.priorityLevel; } getQueueType() { - + return this.queueType; } // Manages a process's execution for the given amount of time @@ -49,19 +51,37 @@ class Queue { // Once a process has received the alloted time, it needs to be dequeue'd and // then handled accordingly, depending on whether it has finished executing or not manageTimeSlice(currentProcess, time) { - + if (currentProcess.stateChanged === true) this.quantumClock = 0; + else if (time < this.quantum) { + this.quantumClock = time; + if (currentProcess.isFinished()){ + this.dequeue(); + } + } else { + this.quantumClock = 0; + if (currentProcess.isFinished()){ + this.dequeue(); + } else { + this.dequeue(); + this.scheduler.handleInterrupt(this, currentProcess, SchedulerInterrupt.LOWER_PRIORITY) + } + } } // Execute the next non-blocking process (assuming this is a CPU queue) // This method should call `manageTimeSlice` as well as execute the next running process doCPUWork(time) { - + let currentProcess = this.peek; + currentProcess.executeProcess(time); + this.manageTimeSlice(currentProcess, time); } // Execute the next blocking process (assuming this is the blocking queue) // This method should call `manageTimeSlice` as well as execute the next blocking process doBlockingWork(time) { - + let currentProcess = this.peek; + currentProcess.executeBlockingProcess(time); + this.manageTimeSlice(currentProcess, time); } // The queue's interrupt handler for notifying when a process needs to be moved to a different queue diff --git a/yarn-error.log b/yarn-error.log index 95c1a36..aebd39f 100644 --- a/yarn-error.log +++ b/yarn-error.log @@ -1,5 +1,5 @@ Arguments: - C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js run test Process.test.js + C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js run test Queue.test.js PATH: C:\Users\diveb\bin;D:\Program Files\Git\mingw64\bin;D:\Program Files\Git\usr\local\bin;D:\Program Files\Git\usr\bin;D:\Program Files\Git\usr\bin;D:\Program Files\Git\mingw64\bin;D:\Program Files\Git\usr\bin;C:\Users\diveb\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files\Oculus\Support\oculus-runtime;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;D:\Program Files\Git\cmd;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Yarn\bin;C:\Program Files\nodejs;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;D:\Program Files\Microsoft VS Code\bin;C:\Users\diveb\AppData\Local\Programs\Python\Python36\Scripts;C:\Users\diveb\AppData\Local\Programs\Python\Python36;C:\Users\diveb\AppData\Local\Programs\Python\Python37\Scripts;C:\Users\diveb\AppData\Local\Programs\Python\Python37;C:\Users\diveb\AppData\Local\Microsoft\WindowsApps;D:\Program Files\Microsoft VS Code\bin;C:\Users\diveb\AppData\Local\Yarn\bin;C:\Users\diveb\AppData\Roaming\npm;C:\Program Files\MongoDB\Server\3.6\bin;C:\Program Files\Heroku\bin;C:\Users\diveb\AppData\Roaming\Python\Python37\Scripts;D:\Program Files\Git\usr\bin\vendor_perl;D:\Program Files\Git\usr\bin\core_perl @@ -3675,7 +3675,7 @@ Trace: Error: Command failed. Exit code: 1 Command: C:\WINDOWS\system32\cmd.exe - Arguments: /d /s /c jest --verbose Process.test.js + Arguments: /d /s /c jest --verbose Queue.test.js Directory: C:\Users\diveb\LambdaSchool\Week19\Multi-Level-Feedback-Queue Output: